将数字添加到字符串

时间:2014-11-17 16:14:28

标签: asp-classic

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

&s=Chicago,IL&s=Memphis,TN&s=Akron,OH&s=Plainfield,IN&s=Dallas,TX&s=Miami,FL&s=Orlando,FL&s=Valdosta,GA&s=Milwaukee,WI

有时它会更大,有时会更小。

我想为每个&s=分配数字,因此上面的示例如下所示:

&s1=Chicago,IL&s2=Memphis,TN&s3=Akron,OH&s4=Plainfield,IN&s5=Dallas,TX&s6=Miami,FL&s7=Orlando,FL&s8=Valdosta,GA&s9=Milwaukee,WI 

但我不知道怎么做,有什么帮助吗?.... 谢谢: - )

我试过这样的东西,但它不起作用???

dim AllLocations
AllLocations="&s=Chicago,IL&s=Memphis,TN&s=Akron,OH&s=Plainfield,IN&s=Dallas,TX&s=Miami,FL&s=Orlando,FL&s=Valdosta,GA&s=Milwaukee,WI"
    dim i
    For i=1 to TotalLocations
    AllLocations=Replace(AllLocations,"&s=","&s" & i & "=")
    Next

    Response.Write(AllLocations)

3 个答案:

答案 0 :(得分:0)

就是这样!

    dim AllLocations
    AllLocations="&s=Chicago,IL&s=Memphis,TN&s=Akron,OH&s=Plainfield,IN&s=Dallas,TX&s=Miami,FL&s=Orlando,FL&s=Valdosta,GA&s=Milwaukee,WI"

' You need to add TotalLocations and have it count how many &s's you have so that the For i 1 to knows where to stop.

        dim i,ArrayOfValues,v,ovo

        ArrayOfValues=Split(AllLocations,"&")
        For i = 1 To TotalLocations
            ovo=Replace(ArrayOfValues(i),"s=","&s" & i & "=")
            Response.write ovo
        Next

答案 1 :(得分:-1)

你可以这样做:

string s = "&s=Chicago,IL&s=Memphis,TN&s=Akron,OH&s=Plainfield,IN&s=Dallas,TX&s=Miami,FL&s=Orlando,FL&s=Valdosta,GA&s=Milwaukee,WI";
int i = 1;
var list = s.Split(',');            
var result = list.Select(x => x.Replace("&s", "&s" + i++));
s = String.Join(",", result);

答案 2 :(得分:-1)

以下是答案:

    var res = "&s=Chicago,IL&s=Memphis,TN&s=Akron,OH&s=Plainfield,IN&s=Dallas,TX&s=Miami,FL&s=Orlando,FL&s=Valdosta,GA&s=Milwaukee,WI";emphis,TN&s=Akron,OH&s=Plainfield,IN&s=Dallas,TX&s=Miami,FL&s=Orlando,FL&s=Valdosta,GA&s=Milwaukee,WI";
  var res = str.split("=");
  for (var i=0; i < res.length; i++) {
    res[i]=res[i]+i;                        
   }      

我也为你写了一支笔,这里是Link