iOS Swift操纵/解析字符串 [英] iOS Swift manipulate/parse string

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

问题描述

我不确定如何在iOS Swift中执行此操作

I'm not sure how to do this in iOS Swift

let test = "fnfsjflsjlkdkfj?v=904kg4"
// search test for ?v= and store everything after ?v= into a new string
let newString = "904kg4"

我想要一切之后?v =成新的字符串,这可能吗?如果是这样,我怎么能完成这个

I want everything after ?v= into a new string, is this possible? if so, how can I accomplish this

推荐答案

使用 rangeOfString 来查找范围?v = 然后使用 substringFromIndex 来获取字符串的其余部分:

Use rangeOfString to find the range of ?v= and then use substringFromIndex to get the rest of the string:

let test = "fnfsjflsjlkdkfj?v=904kg4"
if let range = test.rangeOfString("?v=") {
    let newString = test.substringFromIndex(range.endIndex)
}

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

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