Results 1 to 2 of 2

Thread: extracting strings

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    extracting strings

    im having a problem and its frustrating

    im trying to read entries from a text file, and extract just the city names

    the format is something like this:


    cityname, 213, 45, 7.5
    cityname2, 7, 254, 12, 445

    ..
    ..

    i cant seem to extract the text, the cityname properly. how do i go about extracting the cityname? remember - city names can have spaces inbetween them....i need to get it to from the start to the the first numeric number

    thanks!

  2. #2
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

    Re: extracting strings

    Will the city name ever have a comma in it? If not, you could try using something like this
    Code:
    string		strIn		= "cityname, 213, 45, 7.5\n"+
    							"cityname2, 7, 254, 12, 445";
    string[]	strCities	= strIn.Split('\n');
    
    foreach ( string str in strCities )
    {
    	MessageBox.Show( str.Substring(0,str.IndexOf(",")) );
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width