如何从字符串中提取值
我有一个字符串... "<+36.83452988, -119.79611969> +/- 0.00m (速度 -1.00 mps / 路线 -1.00) @ 11/21/11 8:12:18 PM 印度标准时间“
我希望从中提取坐标。怎么办呢..?
i have a string ... "<+36.83452988, -119.79611969> +/- 0.00m (speed -1.00 mps / course -1.00) @ 11/21/11 8:12:18 PM India Standard Time"
I wish to extract the co-ordinates out of it. how can it be done..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
乔纳斯的简单基本思想是正确的,只是不是用你的语言表达的。
它很简单,最终会为您提供 x 和 y 坐标。
您可以使用 NSString
rangeOfString:
和substringWithRange:
方法自行实现 Jonas 建议,并担心此行后面的空格以下代码将采用您的示例字符串并打破它为您转换为字符串和浮点值,无论您喜欢哪种。
Jonas has the simple fundamental idea right, just not in your language.
It is simple and ends up with an x and y coordinate for you.
You can implement Jonas suggestion yourself with the NSString
rangeOfString:
andsubstringWithRange:
methods and worry about the white space after with this lineThe following code will take your example string and break it into string and float values for you, whichever you prefer.
如果坐标是字符串的第一部分,您应该只获取基于某些字符的子字符串,如下所示:
这是获取 << 之间的部分。和 ,然后在 、 和 > 之间。
问候
乔纳斯
If the coordinates are the first part of your String you should just get substrings bases on certain characters, like that:
This is getting the part between < and , and then between , and >.
Regards
Jonas