小编Tre*_*and的帖子

如何将字符串中所有单词的首字母大写?

首先,我的所有城市都以大写形式返回,因此我将它们切换为小写.我怎样才能将第一个字母作为大写字母?谢谢你的帮助!

List<string> cities = new List<string>();

foreach (DataRow row in dt.Rows)
{
    cities.Add(row[0].ToString().ToLower());

    **ADDED THIS BUT NOTHING HAPPENED**
     CultureInfo.CurrentCulture.TextInfo.ToTitleCase(row[0] as string);
}

return cities;
Run Code Online (Sandbox Code Playgroud)

c# regex

6
推荐指数
2
解决办法
7205
查看次数

Stripe:无法向没有活动卡的客户收费

我正在尝试创建一个客户并使用 Rails 和 Stripe 向该客户收费。客户是在 Stripe 中创建的,但我Cannot charge a customer that has no active card在尝试收费时不断收到错误消息。

我作为 Rails 初学者正在学习条纹教程,所以我不确定从哪里开始。任何帮助将不胜感激。

导轨代码:

def process_payment
    customer = Stripe::Customer.create email: email,
                                       card: card_token

    Stripe::Charge.create customer: customer.id,
                          amount: level.price*100,
                          description: level.name,
                          card: card_token,
                          currency: 'usd'

  end

  def create
    @registration = Registration.new registration_params.merge(email: stripe_params["stripeEmail"],
                                                               card_token: stripe_params["stripeToken"])
    raise "Please, check registration errors" unless @registration.valid?
    @registration.process_payment
    @registration.save
    redirect_to @registration, notice: 'Registration was successfully created.'
  end
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

ruby-on-rails stripe-payments

6
推荐指数
1
解决办法
1万
查看次数

AWS Lambda Node 18:未定义提取,请修复或添加全局提取

我正在尝试从 AWS Lambda 调用 Pagespeed Insights API 以获取结果。lambda 正在运行 Node 18,但仍然无法开始fetch()工作。

它会在 Cloudwatch 中显示“在尝试获取中”,但之后什么也没有。

在我的 Lambda 控制台中,有一条警告称fetch is not defined, please fix or add global fetch. 我的超时时间是 2 分钟,API 调用最多只需要 20 秒即可在浏览器中返回响应。

任何帮助,将不胜感激。

代码

try {
        console.log("inside the try about to fetch", url)
        const response = await fetch(url);
        console.log("response", response)
        const contentType = response.headers.get("content-type");
        console.log("response content type", contentType)
        if (!contentType || !contentType.includes("application/json")) {
          throw new TypeError("Oops, we haven't got JSON!");
        }
        const jsonData = await …
Run Code Online (Sandbox Code Playgroud)

javascript amazon-web-services node.js

6
推荐指数
1
解决办法
1191
查看次数

如何修复400 Bad Request错误?

我得到一个远程服务器尝试运行我的代码时返回错误:(400)Bad Request错误。任何帮助,将不胜感激。谢谢。

    // Open request and set post data
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("myurl.com/restservice/Login");
    request.Method = "POST";
    request.ContentType = "application/json; charset:utf-8";
    string postData = "{ \"username\": \"testname\" },{ \"password\": \"testpass\" }";

    // Write postData to request url
    using (Stream s = request.GetRequestStream())
    {
        using (StreamWriter sw = new StreamWriter(s))
            sw.Write(postData);
    }

    // Get response and read it
    using (Stream s = request.GetResponse().GetResponseStream()) // error happens here
    {
        using (StreamReader sr = new StreamReader(s))
        {
            var jsonData = …
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
1
解决办法
2万
查看次数

如何在HAML中的一行中添加两个变量?

我正在尝试修改一些HAML代码,并希望在同一行上输出两个不同的变量.我怎样才能做到这一点?

%h3= @level.name " $" @level.price
Run Code Online (Sandbox Code Playgroud)

理想情况下,我希望输出采用以下格式: Individual $35

任何帮助将不胜感激.

谢谢!

haml ruby-on-rails

3
推荐指数
1
解决办法
806
查看次数

Ampersand正在逃脱

我的URL有一个问题,即删除了&ref = 1参数和值.是什么导致了这个?

网址是www.mysite.com/folder/category/5&ref=1

   if (!String.IsNullOrEmpty(URLStr))
    {
        if (!String.IsNullOrEmpty(Request["ReturnUrl"]))
        {
            URLStr = Request["ReturnURL"].ToString();
        }
Run Code Online (Sandbox Code Playgroud)

编辑我的网址是Redirect.aspx?ReturnUrl = www.mysite.com/folder/category/5&ref = 1

c#

1
推荐指数
1
解决办法
147
查看次数

如何从控制器调用我的模型?

我试图从我的控制器调用我的模型,但得到错误.错误已开启

new UserModels(id, searchcriteria);

并指出

UserModels does not contain a constructor that takes 2 arguments.

有任何想法吗?

控制器/行动:

    public ActionResult ID(string id)
    {
        ViewBag.Message = "Customer Information";

        string searchcriteria = "userid";

        UserModels model = new UserModels(id, searchcriteria);

        return View();
    }
Run Code Online (Sandbox Code Playgroud)

模型:

public class UserModels
    {
        public UserData user { get; set; }

        public string firstname { get; set; }
        public string lastname { get; set; }

        public string searchvalue {get; set; }
        public string searchcriteria { get; set; }


        public List<UserData> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc-4

1
推荐指数
1
解决办法
57
查看次数

如何使用Coldfusion在字符串中的特定字符之前提取文本?

我有一个看起来像这样的字符串:

5137.02014-10-16T11:26:32-06:001.0.

如何在第一期之前提取文字或数字?它不会总是4个字符.

编辑:

看完源代码后,它似乎产生了这样的:

<wddxpacket version="1.0">
  <header>
   <data>
     <struct>
     <var name="Logo">
       <string></string>
     </var>
     <var name="ID">
       <number>5137.0</number>
     </var>
     <var name="RLink">
       <string></string>
     </var>
     <var name="DateCreated">
       <datetime>2014-10-16T11:26:32-06:00</datetime>
     </var>
     <var name="showTabs">
       <number>1.0</number>
     </var>
    </struct>
</data> 
Run Code Online (Sandbox Code Playgroud)

我只想提取在这种情况下为5137的ID.

谢谢!

coldfusion

1
推荐指数
1
解决办法
977
查看次数

如何遍历每个图像并设置每个图像的大小?

我的下面的代码适用于获取第一个图像的大小,然后添加margin-topmargin-left页面上的每个图像.但是它使用第一张图像作为所有其他图像的基础.我如何循环并使用每个图像的大小来找到它应该用于margin-left和margin-top的值?

$j(document).ready(function () {

//get the image size:
var theHeight = $j("#co-logo img").height();
var theWidth = $j("#logo img").width();

//place them into the image styles:
$j("#co-logo img").css({ 'margin-top': -theHeight / 2 + "px", 'margin-left': -theWidth / 2 + "px" });

});
Run Code Online (Sandbox Code Playgroud)

jquery

0
推荐指数
1
解决办法
1万
查看次数

方法必须具有返回类型

当我尝试构建我的解决方案时,我不断收到此错误.我已经尝试过public string,public但却无法让它发挥作用.有任何想法吗?谢谢!

[WebMethod]
public static LoadCitiesByState(string state)
{
        DataTable dt = SharedDataAccess.GetCities(state);
        List<string> cities = new List<string>();

        foreach (DataRow row in dt.Rows)
        {
            cities.Add(row[0].ToString());
        }
        return cities;

   }
Run Code Online (Sandbox Code Playgroud)

编辑

现在我收到错误:"并非所有代码路径都返回一个值"

编辑二

对不起忘了粘贴我在那里的try&catch.我删除了它,它工作.如果有人想要展示如何使用try&catch来实现它,请尽情享受.

c# asp.net

0
推荐指数
2
解决办法
3723
查看次数