标签: nsstring

Objective-C stringByReplacingOccurrencesOfString with regex expression

我正在尝试使用正则表达式分割包含html代码的字符串:

NSString* regex = @"<.*?>";
NSString* html = @"<span class="test">Test1</span><span class="test">Test2</span><span class="test">Test3</span><span class="test">Test4</span>";

html = [html stringByReplacingOccurrencesOfString:regex withString:@""];
Run Code Online (Sandbox Code Playgroud)

我想删除span-tags.

有任何想法吗?

html regex objective-c nsstring

-1
推荐指数
1
解决办法
2685
查看次数

如何添加字符串

可能重复:
如何在Objective-C中连接字符串?

我有两个字符串,并希望制作第三个字符串,通过连接它们将两者结合起来.

NSString *a = a;
NSString *b = b;
NSString *c = a+b;
Run Code Online (Sandbox Code Playgroud)

问题是Xcode不允许我做+ b,所以我不知道如何添加字符串.我也试过这个:

NSStirng *c = @"%@%@",a,b;
Run Code Online (Sandbox Code Playgroud)

但它也不起作用.请帮我解决这个菜鸟问题!

谢谢!

objective-c string-concatenation nsstring ios

-1
推荐指数
1
解决办法
7643
查看次数

我该如何解析以下字符串

我有一个字符串值.

NSString *myString = @"Latitude:-31.9504140#Longitude:115.8606040";
Run Code Online (Sandbox Code Playgroud)

如何从字符串中检索纬度和经度值并将其指定给坐标

CLLocationCoordinate2D coordinate;
coordinate.Latitude;
coordinate.Longitude;
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsstring coordinates

-1
推荐指数
2
解决办法
261
查看次数

NSString更改格式

我有一个字符串

120505

格式始终如上.然而,内容可能会改变.我希望它是:

05年12月5日

我怎样才能做到这一点?

iphone nsstring

-1
推荐指数
1
解决办法
85
查看次数

如何将字符串转换为NSDate格式?

我想将字符串转换为nsdate格式.

这是我的字符串NSString str = @"2010年6月6日星期日上午5点00分CDT";

我的代码是

        NSDateFormatter * Dateformats= [[NSDateFormatter alloc] init];

        [Dateformats setDateFormat:@"MM/DD/yyyy hh:mm:ss"]; //ex @"MM/DD/yyyy hh:mm:ss" 
        NSDate *myDate=[Dateformats dateFromString:str];
        NSLog(@"%@",myDate);
Run Code Online (Sandbox Code Playgroud)

但它显示为null所以告诉我以MM/DD/yyyy显示日期的方式hh:mm:ss

请各位朋友帮帮我,怎么做

xcode nsstring nsdateformatter ios5

-1
推荐指数
1
解决办法
1万
查看次数

我的代码中处理nsstring的错误

我在这段代码中有错误

NSString *str = @"above string"; //load above string here
NSArray * firstArry = [str componentsSeparatedByString:@"#"];
NSMutableArray *secondArry = [[NSMutableArray alloc] init]; //Will hold the # titles
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; //Will hold the strings related to # title
for(NSString firstArryStr : firstArry)
{
    NSArray *tempArry = [firstArryStr componentsSeparatedByString@"\n"];
    NSMutableArray *titleStingsArry = [[NSMutableArray alloc] init];
    for (int i=0; i< [tempArry count];i++)
    {
        if (i==0)
        {
            NSString *title = [tempArry  objectAtIndex:i];
            [secondArry addObject:title];
            [dict setValue:titleStingsArry  forKey:title];
        } else { …
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c uitableview nsstring

-1
推荐指数
1
解决办法
76
查看次数

替换NSString的值

我试图将NSString中月份的名称替换为其两位数字值的名称,例如"January"=>"01","February"=>"02".我使用的方法如下:

if (mois==@"january") { mois=@"01";}   
if (mois==@"February") { mois=@"02";}
Run Code Online (Sandbox Code Playgroud)

......但它不起作用.我该怎么做这个替换?

iphone objective-c nsstring

-1
推荐指数
1
解决办法
138
查看次数

如何用点分割字符串?

我有一个NSString string = @"abce20aa.fasgfh458sfs456456";

我怎么才能abce20aa进入另一个字符串?

objective-c nsstring

-1
推荐指数
1
解决办法
860
查看次数

我的iOS应用程序不会遍历我的字符串

我意识到这是一个非常基本的问题,其他帖子似乎没有帮助,因为我对此很新.我很好奇为什么A.)我的for循环不会遍历我的字符串(问题),为什么B.)它只打印最后一个问题"你的姓氏是什么?" 当我点击我的目标操作按钮时,在我的iOS模拟器上.我的所有关系都是正确的,显然如果它的建筑物,我的.h中的所有东西都可以.

我很感激帮助!

- (IBAction) question;
{
    for (int i = 0; i < 5; i++)
    {
        questionLabel.text = @"Whats your name?";
        questionLabel.text = @"Whats your age?";
        questionLabel.text = @"Whats your height?";
        questionLabel.text = @"Whats your weight?";
        questionLabel.text = @"Whats your last name?";

    }
}
Run Code Online (Sandbox Code Playgroud)

objective-c nsstring ios

-1
推荐指数
1
解决办法
132
查看次数

分配后RetainCount为-1​​?

请不要标记重复: - 我创建了几行

NSString *str = [[NSString alloc] init];
str = @"Test";
NSLog(@"%d",[str retainCount]);
Run Code Online (Sandbox Code Playgroud)

和输出是-1.请解释.

nsstring retaincount

-1
推荐指数
1
解决办法
202
查看次数