I have a string that contains Chinese characters, English and numbers. I want to replace numbers and English with *. How do I do this? Usually it is a simple replacement. This requires regular expressions
PHP中文网2017-07-06 10:36:30
NSString *content = @"哈哈哈哈test哈t123哈哈哈哈";
NSLog(@"替换前--- %@",content);
NSRegularExpression *regularExpression = [NSRegularExpression regularExpressionWithPattern:@"[a-zA-Z0-9]" options:0 error:nil];
content = [regularExpression stringByReplacingMatchesInString:content options:0 range:NSMakeRange(0, content.length) withTemplate:@"*"];
NSLog(@"替换后--- %@",content);
巴扎黑2017-07-06 10:36:30
Isn’t this okay?
var str = '123你好呀hehe';
console.log(str.replace(/\w/g, '*'));
迷茫2017-07-06 10:36:30
Loop it over and judge the ASCII code directly. Use c syntax to compare and change characters one by one