Reputation: 33
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.
Upvotes: 3
Views: 92
Reputation: 3
string FileNameOrginal = "lighthouse-126.jpg";
string file1 = FileNameOrginal.Split('-')[0];
string file2 = FileNameOrginal.Split('-')[1];
Upvotes: 0
Reputation: 21
Instead of:
string[] strDataArray = FileNameOrginal.Split("-");
Try
string[] strDataArray = FileNameOrginal.Split('-');
Upvotes: 0
Reputation: 67898
So the issue is that you need an array for an input, like this:
string[] strDataArray = FileNameOrginal.Split(
new string[] { "-" },
StringSplitOptions.None);
Upvotes: 0
Reputation: 415600
You just need a character instead of string:
string[] strDataArray = FileNameOrginal.Split('-');
Upvotes: 6