简体   繁体   中英

Remove the first 4 letters from string

Hi I am having a string as G531 Other Dough Products .

Here I want only Other Dough Products , reply me with code.

I tried with substring but that is not working.

Thanks in advance .

You don't actually say what you tried but substringFromIndex :

NSString *str = @"G531 Other Dough Products";
str = [str substringFromIndex:5];

should do the trick.

You'll probably find that you want to use 5 unless you want the leading space in your new string.

NSString* s = [@"G531 Other Dough Products" substringFromIndex:5];

尝试使用“ substringFromIndex”(请参阅文档

He He, you can also do this as below,

NSString * newString = [NSString stringWithCString:(const char*)&"G531 Other Dough Products"[5] encoding:NSUTF8StringEncoding];
NSLog(@"%@", newString); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM