ios NSString中的子字符串[已关闭]

ahy6op9u  于 2023-08-08  发布在  iOS
关注(0)|答案(5)|浏览(71)

已关闭。此问题需要更多focused。它目前不接受回答。
**希望改进此问题?**更新问题,使其仅针对editing this post的一个问题。

9年前关闭。
Improve this question
我使用的是NSString,我想得到它的一个子字符串,其中包含我的字符串的前20个字符。我怎么能这么做呢?

soat7uwm

soat7uwm1#

可以使用substringToIndex

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

字符串

41ik7eoe

41ik7eoe2#

NSString *str = @"123456789012345678901234";
NSString *subStr = [str substringWithRange:NSMakeRange(0, 20)];

字符串

gajydyqb

gajydyqb3#

NSString *string = @"I am having a simple question.I am having NSString and i want a substring of it that contains first 20 ";
NSString *first20CharString = [string substringToIndex:20];

字符串

wnavrhmk

wnavrhmk4#

试试这个:

NSString *string = @"This is for testing substring from string";
    NSInteger intIndex = 20;
    NSLog(@"%@", [string substringToIndex:intIndex]);

字符串

jvidinwx

jvidinwx5#

检查以下内容:

NSString *strTmp = @"This is test string to check substring.";
NSInteger intIdx = 20;
NSLog(@"%@", [strTmp substringToIndex:intIdx]);

字符串
这对你会有帮助的。
干杯!

相关问题