delimited string test

  • Thread starter Thread starter rodchar
  • Start date Start date
R

rodchar

hey all,
let's say you have a delimited string value of

String value = val1,val2,val3;

and you do something like the following

String s = value.split(',')[3];

well this is outside the range of index, so how can i say if this does occur
just make it an empty string and proceed?

thanks,
rodchar
 
rodchar said:
hey all,
let's say you have a delimited string value of

String value = val1,val2,val3;

and you do something like the following

String s = value.split(',')[3];

well this is outside the range of index, so how can i say if this does occur
just make it an empty string and proceed?
Test for it.

string[] values = value.split(',');
string s = values.Length > 3 ? values[3] : "";
 
hey all,
let's say you have a delimited string value of

String value = val1,val2,val3;

and you do something like the following

String s = value.split(',')[3];

well this is outside the range of index, so how can i say if this does occur
just make it an empty string and proceed?

thanks,
rodchar

What about by checking?
string[] parts = myStr.split( new char[]{','});
string d = ( index < parts.Length ) parts[index]: "";
if (
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

number of values in enum 2
Expression parser 4
RegEx and parsing a URL 1
Splitting a String 28
flip this query 3
Delegates when to use 3
String Conversion to Int 14
Excel 2007 - Pivot Table Report Values fields 1

Back
Top