帮助进行字符串操作 [英] Help With String Manipulation

查看:96
本文介绍了帮助进行字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,[我是我要把这个长字符串剥离成段(GPRMC,094810.00,A,0905.52005,N,00728.55781,E,000.0,000.0,150911,04.0,W,A * 17OK) .
就像在每个逗号前存储数字一样,例如:String SateliteTime = 094810.00;字符串LatitudeHemispher = 00728.55781.t.c

谢谢您的期待.

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.

推荐答案

嗨.
字符串str ="a,b,c,d,e,f";
string [] streach = Split(str,'','');
然后您的字符串将被拆分为一个具有a,b,c,d,e,f
的数组 streach [0] = a;
streach [1] = b;
这样的
希望这对您有帮助!
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!


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");

好的,现在您必须将字符串从"geoInfoList"中拉出,并做正确的事将它们转换为double,float或integer值,或您的应用程序所需的任何内容.

为什么将使用"Split"产生的字符串数组转换为通用List< string> ;? ?因此,我可以使用方便的"IndexOf"运算符来查找给定的字符串,如上所示:例如,如果我知道"N"的位置,那么我知道列表中的下一项就是纬度. >
当然,您可以只使用"Split"产生的简单字符串数组.

如果我知道我的数据始终是固定格式",那么我就可以总是以拆分字符串数组中的第六个条目(索引号为5)为例,以您的字符串为例. -strings是纬度"的值,那么我将不使用convert到List< string> ;,因为我不需要使用IndexOf()来定位特定数据.

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.


这篇关于帮助进行字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆