For Programmers: Free Programming Magazines  


Home > Archive > C# > August 2004 > split string into boolean array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author split string into boolean array
MattB

2004-08-03, 9:07 am

Is there a good way to.....

Get a comma delimited string like
strBool = "false,true,false,false,true,false"

split it into an array

char[] chrsplit = ",".ToCharArray();

string[] myBoolArr = strBool.Split(chrsplit);

and then turn this into a boolean array bool[]


Thanks for any thoughts,
Matt
David Logan

2004-08-04, 9:06 am

MattB wrote:
> Is there a good way to.....
>
> Get a comma delimited string like
> strBool = "false,true,false,false,true,false"
>
> split it into an array
>
> char[] chrsplit = ",".ToCharArray();
>
> string[] myBoolArr = strBool.Split(chrsplit);
>
> and then turn this into a boolean array bool[]
>
>
> Thanks for any thoughts,
> Matt


I looked through the Convert class and Array class, and did not see
anything for applying a method to all elements of an array. All I came
up with was the method:


public bool[] StringArrayToBool(String str)
{
String[] boolstringarray = str.Split(new char[]{','});
bool[] boolarray = new bool[boolstringarray.Length];
for(int x=0;x<boolstringarray.Length;x++)
boolarray[x]=Convert.ToBoolean(boolstringarray[x]);
return boolarray;
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com