Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, (sorry for my english!)

 

I have a file like this:

"string1","string2","string3","string4"....

 

I want the string between the " without the " and the ,

 

In php, my co-worker used this:

preg_match_all('|"([^"]*)",?|i', $content, $matches);

 

$content = the file

 

We upgrade in C#

With c# I use something like this:

MatchCollection Matches = Regex.Matches(fiche, "\"([^\"]*)\",?", RegexOptions.IgnoreCase);

 

I put the result in an array:

for (int i = 0; i < Matches.Count; i++)

{

array.Add(Matches[0].Groups.ToString();

}

 

I have this result

0: "string1",

1: string1

2: (empty)

3: (empty)

....

 

But I have the right count of string.

 

I really don't understand what's wrong.

 

Thank you

  • Leaders
Posted

Okay... I'm not particularly familiar with either c# or regular expressions, so don't yell at me if it doesn't run right, but I whipped out my #develop, my Microsoft Visual Basic .NET, and made this and after a couple minutes of adding forgotten semi-colons and brackets and fixing my casing, I came up with this.

 

void example() {
string filetext  = "\"string1\",\"string2\",\"string3\",\"string4\"";
MatchCollection Matches = Regex.Matches(filetext, "\"([^\"]*)\",?", RegexOptions.IgnoreCase);
string[] x = new string[Matches.Count];
for (int i = 0; i < Matches.Count; i++) {
	x[i] = Matches[i].Groups[1].ToString();
}
//x[] now equals an array of the matches without the quotes
}

 

Don't know why that came out double spaced...

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...