TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pablo Costa
NA
24
4.8k
Regex group matches not updating
Feb 21 2016 8:33 PM
I've made a simple regex to extract all numbers inside square brackets.
It works , no problems - also the foreach loop (in order to get each group of numbers) works okay.
My problem is that: After i add more code (some stuff i gotta do with the values) the regex stops updating.
Ex: Lets suppose it extracted:
12346
24566
88765
If i don't add much code inside the foreach , each match will have a new number group. But if i add the rest of my code, the group will repeat always (not updating). I hope i've expressed what i meant to heh.
Any help will be appreciated. Thanks a lot !
Here's my code:
foreach (Match m in matches)
{
Double[] numbers;
string aux;
aux = m.Groups[1].ToString();
aux = Regex.Replace(aux, @"\s+", "|");
string[] numbers_str = aux.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
numbers = new Double[numbers_str.Length];
//**********************
//if i add any of the code below this line regex matches won't update.
//***********************
for (int j = 0; j < numbers.Length; j++)
{
numbers[j] = Double.Parse(numbers_str[j], CultureInfo.InvariantCulture);
//Converts each number on the string to a Double number, store it in a position
//in the Double array
numbers[j] = numbers[j] / 100; //Needed calculus
numbers[j] = Math.Round(numbers[j], 3); //Storing numbers rounded
}
string values = String.Join(" ", numbers.Select(f => f.ToString()));
var info = new List<xmldata>();
if (i < colors_str.Length)
{
info.Add(new xmldata
{
colorname = colors_str[i],
colorvalues = numbers.ToString(),
});
break;
}
i++;
}
SAMPLE TEXT (the string s2):
HDMInkB [0.000000 0.410713 2.845792 3.988575 4.526777 2.584811 0.446784 3.604538 4.245287 4.266978 1.825807 1.183750 3.844300 4.258716 3.706854 1.238119 2.012574 3.971962 4.602654 3.133026 0.582939 2.877447 4.176142 4.383155 2.513122 0.606338 3.622515 4.245274 4.119257 1.749254 0.512194 0.000000 ].HDMInkX [0.000000 3.611394 4.155595 1.382772 1.382821 1.382718 9.560535 1.381371 1.385395 1.383025 2.529139 8.453050 1.417584 1.382647 1.382727 3.687436 7.259602 1.383159 1.382736 1.383132 7.845152 3.100295 1.381322 1.380878 1.385115 9.561936 1.382674 1.423072 1.414970 2.846161 1.216019 0.000000 ].
Reply
Answers (
0
)
Windows form.
how to write linq query to get collection of an object