开发者

Split after a number of character

I'm working with latlon values for YM4R with google maps. I need to know how to split a string after 10 characters.

Here is an example string "51.5261658-0.0810102" if I know split the string after the 10th character开发者_运维百科, I would be able to get separate lat lon values.

Has anyone got any ideas?


Why not just split on the -?

str = "51.5261658-0.0810102"
values = str.split("-")
lat = values[0]
lon = values[1]

Here we slice off the first 10 characters

str = "51.5261658-0.0810102"

#remove the - if it's there
str.gsub!("-","")
lat = str.slice!(0..9)
lon = str
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜