Remove Lines in a string

I have a string that looks like this

Telephone number: 123-123-124
Service address:
1234 My Street
City, State

I need to extract the 3rd line and the city and state to separate variables. Does anyone know how to do this?

Hi,

Hope the following helps you.

address = yourString.Split(vbCrLf.ToCharArray,StringSplitoptions.RemoveEmptyEntries)(2)
cityAndState = yourString.Split(vbCrLf.ToCharArray,StringSplitoptions.RemoveEmptyEntries)(3)

Regards,

Hi Jonathan,

If the string is as your example, then you’ll need to perform several splits:

  1. Split the string using the NewLine as separator
    eg. yourString.Split( new String() {Environment.NewLine} , StringSplitOptions.None )
  2. Then split the 2nd element of the resulting array using the blank space as a separator.
  3. For City and State you’ll have to perform the same using the comma (,) as a separator.

Best,

Pedro Arroyo