2012-08-06 46 views
0

嗨我有一个字符串的问题。我想补充:NSString包含任何“。*”来显示它

NSString *termo = [NSString stringWithFormat:@"%@%@: %@ ", @"~00000000:",nazwa, @".*"]; 

这个*是任何东西。我如何使用它?

+0

你想要发生什么? – 2012-08-06 14:28:41

+0

我很难说出你在问什么。你能澄清你想要输出的代码是什么吗? – 2012-08-06 14:28:55

回答

0

你的问题很不清楚,但是你的评论。“我有一些字符串,这是我从服务器获取我想这个解析这个字符串”似乎在暗示:

    ,你必须从某处获得一个字符串
  1. ;
  2. 此字符串应包含您存储在变量nazwa中的文本;和
  3. 你希望找到跟随nazwa包含的文字。

如果猜测是正确的,那么下面的代码片段可能帮助,它包含您需要验证输入实际上包含了你在找什么,后面的东西任何检查 - 检查所用的方法的文档,看看他们返回什么,如果他们没有找到文字等:

// a string representing the input 
NSString *theInput = @"The quick brown fox"; 
// nazwa - the text we are looking for 
NSString *nazwa = @"quick"; 
// locate the text in the input 
NSRange nazwaPosition = [theInput rangeOfString:nazwa]; 
// a range contains a location (offset) and a length, so 
// adding these finds the offset of what follows 
NSUInteger endofNazwa = nazwaPosition.location + nazwaPosition.length; 
// extract what follows 
NSString *afterNazwa = [theInput substringFromIndex:endofNazwa]; 
// display 
NSLog(@"theInput '%@'\nnazwa '%@'\nafterNazwa '%@'", theInput, nazwa, afterNazwa); 

此输出:

theInput 'The quick brown fox' 
nazwa 'quick' 
afterNazwa ' brown fox' 

HTH

0

.*是用来匹配任何一个正则表达式,但如果你只是想看看如果NSString不是空的,你最好不要做这样的事情

![string isEqualToString:@""] 
+0

我想显示在nazwa之后的东西:。而已。 – virtualer007 2012-08-06 14:34:54

+0

我用这个温度来比较蜇伤。 – virtualer007 2012-08-06 14:35:26

+0

do'[NSString stringWithString:@“。*”]'...我不知道你为什么还有其他东西,那么 – 2012-08-06 14:36:26

相关问题