如何比较第二个字母?
我使用 RegexKitLite FrameWorks。
NSString *str = [NSString stringWithString:@"Welcome"];
NSString *newStr [NSString string];
//RegexKitLite.h reference.
newStr = [str stringByReplacingOccurrencesOfRegex:<How To Expression?> withString:@"?"];
我想将“欢迎”转换为 => “W??????”;更一般地说,适用于 Apple
、Banana Cake
、Love
、Peach
、Watermelon
。 .. 我想隐蔽地
Apple => A????
Banana => B?????
Cake => C???
Love => L???
制作一个这些模式(仅显示 HeadLetter)...所有单词都存储在 NSMutableArray 中,所以我访问
[arr objectAtIndex:i] stringByReplacingOccurrencesOfString:<Expression> withString:@"?"];
如何将第二个字母与正则表达式进行比较?
I Use RegexKitLite FrameWorks.
NSString *str = [NSString stringWithString:@"Welcome"];
NSString *newStr [NSString string];
//RegexKitLite.h reference.
newStr = [str stringByReplacingOccurrencesOfRegex:<How To Expression?> withString:@"?"];
I want "Welcome" convert to => "W??????"; More generally, for Apple
, Banana Cake
, Love
, Peach
, Watermelon
... I want to covert
Apple => A????
Banana => B?????
Cake => C???
Love => L???
I Make a These Pattern (HeadLetter only Show)... All Word is Stored In NSMutableArray So I access
[arr objectAtIndex:i] stringByReplacingOccurrencesOfString:<Expression> withString:@"?"];
How to compare Second letter With RegularExpression?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要为此使用正则表达式。只需执行以下
操作即可获得更多选项,另请参阅
NSString
方法stringByReplacingOccurrencesOfString:withString:options:range:
对于您描述的更一般的情况,这可以通过类似的
来实现NSString
方法,例如You don't need to use a regex for this. Simply do
For more options, also see the
NSString
methodstringByReplacingOccurrencesOfString:withString:options:range:
For the more general case you describe, this can be achieved by similar
NSString
methods, e.g.看看你的问题,我不知道你为什么坚持使用reg-ex?
[NSString characterAtIndex:] 将允许您查看字符串中任何位置的特定字符。
Looking at your question, I'm not sure why you're insisting on using reg-ex?
[NSString characterAtIndex:] will allow you to look at a particular character at any position within a string.