how do i extract integer values in an int array from this string
1840 1841
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Mar 5, 2010, 10:01 PM
using System.Text.RegularExpressions;
string Data = "1840 1841 ";
//Get All Integer In Array
Regex rex = new Regex("[0-9]+");
int[] Array = new int[rex.Matches(Data).Count];
int i=0;
foreach (Match m in rex.Matches(Data))
{
Array[i++] = int.Parse(m.Value.ToString());
}
Sam HobbsPosted Mar 8, 2010, 4:04 PM
I am not sure what happened to the attachment to my previous post, but I tried a few times to upload it again. I will try again to upload it.
Desi GalPosted Mar 8, 2010, 10:47 AM
@theLizard:your answer separates out individual digit in an array,thanks though.
@Sam:thanks ,I will try out ur solution
Sam HobbsPosted Mar 6, 2010, 4:40 AM
Note that XmlSerializer can read from a StringReader stream instead of a file stream if you need to read from memory instead of storage.
theLizardPosted Mar 5, 2010, 5:24 PM
private void doTest()
{
int[] iArr = new int[0];
for(int i=0; i < test.Length; i++)
{
if( Char.IsDigit(test, i) )
{
Array.Resize(ref iArr, iArr.Length+1);
iArr[iArr.Length-1] = int.Parse(test[i].ToString());
}
}
}
string manipulation is a very important quality.