0

Ill lose to much time since i don`t have too much experience in manipulating with strings/chars.

i have

string original = "1111,2222,"This is test work")";

i need

string first = "1111";
string second = "2222";
string name = "This is test work";

C# ASP.NET

2 Answers 2

3

Use string.Split() - your pattern is simple (split on comma), there is no need to use a RegEx here:

var parts = original.Split(',');
first = parts[0];
second = parts[1];
name = parts[2].TrimEnd(')'); //in case you really wanted to remove that last bracket
Sign up to request clarification or add additional context in comments.

4 Comments

@AbeMiessler: Fortunately I don't have to since string.Split is using a params char[] separator as input - try it out.
+1, I stand corrected! Could you explain what you mean by params char[] separator?
damn i forgot that i can use split :))). Thanks ! Solved
@Abe: A method that accepts a params array allows you to pass variable number of parameters separated by comma instead of an array, it it just syntactical sugar
1

Use the String.Split method:

string[] values = original.Split(new Char [] {','});

This will break apart your string at every comma and return a string array containing each part. To access:

string first = values[0];
string second = values[1];
string name = values[2];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.