ios - How to replace both numbers and English in a string with *
PHP中文网
PHP中文网 2017-07-06 10:34:30
0
4
4186

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中文网
PHP中文网

认证高级PHP讲师

reply all(4)
Ty80
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);

学霸
var str = '123你好呀hehe';
console.log(str.replace(/\w|\d/gi, '*'))
巴扎黑

Isn’t this okay?

var str = '123你好呀hehe';
console.log(str.replace(/\w/g, '*'));
迷茫

Loop it over and judge the ASCII code directly. Use c syntax to compare and change characters one by one

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template