Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone, [I am I want to to strip-off this long string into sections (GPRMC,094810.00,A,0905.52005,N,00728.55781,E,000.0,000.0,150911,04.0,W,A*17OK).
Like store the numbers before each comma, Example: String SateliteTime = 094810.00; string LatitudeHemispher = 00728.55781.t.c

Thanks in-anticipation.
Posted

Hi..Here is the solution..

String str="a,b,c,d,e,f";
string[] streach=Split(str,',');
then ur string will split into a array with a,b,c,d,e,f
streach[0]=a;
streach[1]=b;
like that
hope this helps!
 
Share this answer
 
XML
private string geoInfo = @"(GPRMC,094810.00,A,0905.52005,N,00728.55781,E,000.0,000.0,150911,04.0,W,A*17OK)";

List<string> geoInfoList = geoInfo.Split(',').ToList<string>();

int ndx = geoInfoList.IndexOf("N");
Okay, now you are going have to pull strings out of the 'geoInfoList' and do the right thing to convert them to double, float, or integer values, or whatever is required for your application.

Why did I convert the String Array produced by using 'Split' to a generic List<string> ? So I could use the handy 'IndexOf' operator to find a given string, as shown above: if I know the position of "N," I know the next item in the List is the latitude, for example.

Of course you could just use the simple array of strings produced by 'Split.'

If I knew my data was always in a 'fixed format,' so that I could always rely, to use your string as an example, on the sixth entry (at index #5) in the split-into-array-of-strings being the value for 'Latitude, then I wouldn't use convert to a List<string>, because I wouldn't need to use IndexOf() to locate specific data.
 
Share this answer
 
v2
Comments
Manas Bhardwaj 17-Sep-11 8:45am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900