delimited string test

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?cm9kY2hhcg==?=

    delimited string test

    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
  • Jeroen Mostert

    #2
    Re: delimited string test

    rodchar wrote:
    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] : "";

    --
    J.

    Comment

    • Ignacio Machin ( .NET/ C# MVP )

      #3
      Re: delimited string test

      On Mar 26, 4:31 pm, rodchar <rodc...@discus sions.microsoft .comwrote:
      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 (

      Comment

      • =?Utf-8?B?cm9kY2hhcg==?=

        #4
        RE: delimited string test

        thanks everyone for the help,
        rod.

        "rodchar" wrote:
        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

        Comment

        Working...