Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the function of intercepting Chinese characters in string by iOS

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how iOS intercepts Chinese characters in strings. I hope you will get something after reading this article. Let's discuss it together.

The details are as follows

Write a simple example to intercept a string from the first Chinese character. Paste the code below:

# import "ViewController.h" @ interface ViewController () @ end@implementation ViewController- (void) viewDidLoad {[super viewDidLoad]; NSArray * array = @ [@ "03-151apple", @ "412banana", @ "# 7tea 15 oranges"]; for (int I = 0; I

< array.count; i++) { NSString *chineseStr = [self getChineseStringWithString:array[i]]; NSLog(@"chineseStr = %@\n", chineseStr); }}- (NSString *)getChineseStringWithString:(NSString *)string{ //(unicode中文编码范围是0x4e00~0x9fa5) for (int i = 0; i < string.length; i++) { int utfCode = 0; void *buffer = &utfCode; NSRange range = NSMakeRange(i, 1); BOOL b = [string getBytes:buffer maxLength:2 usedLength:NULL encoding:NSUTF16LittleEndianStringEncoding options:NSStringEncodingConversionExternalRepresentation range:range remainingRange:NULL]; if (b && (utfCode >

= 0x4e00 & & utfCode

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report