Parsing a string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following string format that I am trying to parse

1-1-
1-1-
1-1-1
2-222-
22-2-3

or

xx-xxx-x

from which I would like to place xx into an ArrayList, xxx into an ArrayList2 and xx into an ArrayList3. The '-' are delimiters

Any suggestion would deeply help

Sincerely

Tony D. Abe
 
You can use String.Split which returns an array or strings. You'd pass in
the string and the delimmiter. If you know you have three "-" then your
array will be 0-2 HTH,
Bill

P.S. A regex is much better suited to these tasks if they are any more
complex than this, but if you are sure that you'll have the delimmited and
it'll never appear where the numbers are, then you're good to go.
Tony D. Abel said:
I have the following string format that I am trying to parse.

1-1-1
1-1-2
1-1-10
2-222-1
22-2-31

or

xx-xxx-xx

from which I would like to place xx into an ArrayList, xxx into an
ArrayList2 and xx into an ArrayList3. The '-' are delimiters.
 
Thanks William.

I will use this suggestion.

Have a great code day.

Sincerely,

Tony D. Abel
 
Again thanks for your input William. This is the solution that I created for my problem. I trust that it will provide someone with help

Sincerely

Tony D. Abe


Int32 loadArrays = 0
char[] delimiters = new char[] {'-'}
string[] substringsBookChapVerID = null
string strBookChapVerID
ArrayList chapterList = new ArrayList()
ArrayList verseList = new ArrayList()

/// <summary
/// Get the columns primary ID string from the ro
/// </summary
foreach ( DataRow bibleRow in bibleDataset.Tables[BibleColumnName].Rows

strBookChapVerID = (string) bibleRow[BibleColumnName];
substringsBookChapVerID = strBookChapVerID.Split( delimiters );
/// <summary
/// Get the book, chapter and verses substring
/// </summary
foreach ( string number in substringsBookChapVerID )


/// <summary
/// Save the book, chapter and verses substrings for sortin
/// </summary
switch ( loadArrays

case 0
bookNumber = number
loadArrays++
break

case 1
if ( number == "0"

loadArrays++
break


if ( chapterList.Count == 0
{ chapterList.Add( number );
loadArrays++
break

else if ( chapterList.IndexOf( number ) <= -1
{
chapterList.Add( number ); loadArrays++
break


loadArrays++
break

case 2
if ( number.TrimEnd( ' ' ) == "0"

loadArrays = 0
break


verseList.Add( number.TrimEnd( ' ' ) )
loadArrays = 0
break

} // end switch loadArray
} // end number
} // end bibleRo
 
Back
Top