ios - 来自 NSString 的子字符串

标签 ios nsstring substring

<分区>

我正在使用 NSString,我想获取它的一个子字符串,其中包含我的字符串的前 20 个字符。我该怎么做?

最佳答案

您可以使用substringToIndex

NSString *mystring = @"This is a test message having more than 20 characters";
NSString *newString = [mystring substringToIndex:20];
NSLog(@"%@", newString);

关于ios - 来自 NSString 的子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14767167/

相关文章:

java - 在 Java 中使用子字符串从字符串中获取整数和字符?

ios - 分支深层链接未打开应用程序

ios - 使用 RxSwift 和 MVVM 显示事件指示器

c - 如何在 C 中编写一个返回 char * 部分的函数?

ios - 创建一个 NSString 的集合/数组以与 stringByReplacingOccurrencesOfString 一起使用

objective-c - NSString : easy way to remove UTF-8 accents from a string?

sql - 如何从描述中提取数字(价格)

ios - UIWebView 的导航栏

ios - 我的字典是空的,尽管它有值

ios - 获取 NSString 在字符串中的位置 - iOS