3

I have this string here:

String FileNameOrginal = "lighthouse-126.jpg";

and I am trying to split the string into 2, seperating it with "-"

I have tried the following, but I get a syntax error on the Spilt:

String FileNameOrginal = drProduct["productHTML"].ToString();
string[] strDataArray = FileNameOrginal.Split("-");

Please Help, I do not understand what I am doing wrong.

4

4 回答 4

6

你只需要一个字符而不是字符串:

string[] strDataArray = FileNameOrginal.Split('-');
于 2013-07-25T15:33:30.107 回答
0

所以问题是您需要一个输入数组,如下所示:

string[] strDataArray = FileNameOrginal.Split(
    new string[] { "-" },
    StringSplitOptions.None);
于 2013-07-25T15:34:21.070 回答
0
  string FileNameOrginal = "lighthouse-126.jpg";
        string file1 = FileNameOrginal.Split('-')[0];
        string file2 = FileNameOrginal.Split('-')[1];
于 2013-07-25T15:49:05.593 回答
0

代替:

string[] strDataArray = FileNameOrginal.Split("-");

尝试

string[] strDataArray = FileNameOrginal.Split('-');
于 2013-07-25T15:34:53.630 回答