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.

0

4 Answers 4

6

You just need a character instead of string:

string[] strDataArray = FileNameOrginal.Split('-');
Sign up to request clarification or add additional context in comments.

1 Comment

Agreed, note the use of single quotes instead of double quotes.
0

So the issue is that you need an array for an input, like this:

string[] strDataArray = FileNameOrginal.Split(
    new string[] { "-" },
    StringSplitOptions.None);

1 Comment

While this is true, for his use case, I think using a character is simpler.
0

Instead of:

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

Try

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

Comments

0
  string FileNameOrginal = "lighthouse-126.jpg";
        string file1 = FileNameOrginal.Split('-')[0];
        string file2 = FileNameOrginal.Split('-')[1];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.