小编Eam*_*orr的帖子

目标C:将Array Element与String进行比较

问候,

我试图简单地将NSString与NSArray进行比较.

这是我的代码:

NSString *username=uname.text;
    NSString *regex=@"^[a-zA-Z0-9-_.]{3,20}$";
    NSArray *matchArray=nil;
    matchArray=[username componentsMatchedByRegex:regex];
    if(matchArray[0] == "asdf"){   //this line causes the problem!
        NSLog(@"matchArray %@",matchArray);
    }
Run Code Online (Sandbox Code Playgroud)

我得到"无效的操作数到二进制=="错误.

我该如何比较字符串?

提前谢谢了,

string iphone compare objective-c

0
推荐指数
1
解决办法
5023
查看次数

目标C:存储所有视图中都可访问的变量

问候,

我正在尝试编写我的第一个iPhone应用程序.我需要能够访问所有视图中的数据.用户登录时存储数据,此后需要对所有视图可用.

我想创建一个静态类,但是当我尝试访问静态类时,我的应用程序在控制台上没有输出时崩溃了.

是将数据写入文件的唯一方法吗?或者是否有其他我没有想到的清洁解决方案?

提前谢谢了,

iphone static class objective-c

0
推荐指数
1
解决办法
2245
查看次数

C++:奇怪的std :: cout错误

我认为这是一个相对简单的事情:用"斜杠"附加"www.google.ie",并用"http://"预先挂起,产生一个值为"http://"的字符串www.google.ie/".不,这不是作业...(我知道)

现在这是我的代码:

std::string line=split1[0];   //split1[0] is "Host: www.google.ie"
std::vector<std::string> split2;
boost::split(split2,line,boost::is_any_of(" "));
boost::erase_all(split2[1],"\n");
std::cout<<"split2[1]:"<<split2[1]<<std::endl;   //outputs www.google.ie ok
fURL="http://"+split2[1]+"/";
//fURL="http://www.google.ie/";   //this is what I want fURL to be!
std::cout<<std::endl;   //just for some testing
std::cout<<std::endl;
std::cout<<std::endl;
std::cout<<std::endl;
std::cout<<std::endl;
std::cout<<"fURL:"<<fURL<<std::endl;   //should output: http://www.google.ie/?
Run Code Online (Sandbox Code Playgroud)

这是我奇怪的输出:

split2[1]:www.google.ie





/URL:http://www.google.ie
Run Code Online (Sandbox Code Playgroud)

我不知道'/ URL:'中的'/'来自哪里.就好像我指定的尾部斜线以某种方式被固定在前面.我真的不明白这是怎么可能的......

在Linux Ubuntu上使用g ++ 4.5.2.

任何见解都非常感激.

提前谢谢了,

c++ string boost

0
推荐指数
1
解决办法
336
查看次数

Objective-C:无法填充UITableView - 尝试了一切

我正试图在XCode 4.1中填充一个简单的uitableview.

这是MessagesInbox.h:

#import <UIKit/UIKit.h>

@interface MessagesInbox : UITableViewController <UITableViewDelegate,UITableViewDataSource>{
    NSMutableArray *listData;
    IBOutlet UITableView *table;
}
@property (nonatomic,retain) UITableView *table;
@property (nonatomic, retain) NSArray *listData;

@end
Run Code Online (Sandbox Code Playgroud)

这是MessagesInbox.m:

#import "MessagesInbox.h"

@implementation MessagesInbox
@synthesize listData,table;

- (void)loadView{   
}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
} …
Run Code Online (Sandbox Code Playgroud)

macos objective-c xcode4

0
推荐指数
1
解决办法
2380
查看次数

将字符串提取到符号

我需要'在字符串中找到所有符号,然后从字符串的开头提取所有字符到第一次出现'.例如:我有Jon's,我需要得到Jon.谁能帮助我?

javascript jquery

0
推荐指数
1
解决办法
266
查看次数

Bash stdin - 我正在失去所有换行符

所以我有这个bash脚本来加密:

#!/bin/bash
#encrypt.sh

fn=$1
if [ $# -eq 0 ]
  then
    echo "Filename required..."
fi

echo "Type text. Hit Ctrl-d when done"
keyvariable=$(cat)

echo -e $keyvariable | gpg --symmetric --cipher-algo AES256 > $fn
Run Code Online (Sandbox Code Playgroud)

我有这个脚本来做解密:

#!/bin/bash
#decrypt.sh

fn=$1
if [ $# -eq 0 ]
  then
    echo "Filename required..."
fi

cat $fn | gpg --decrypt
Run Code Online (Sandbox Code Playgroud)

例:

sh encrypt.sh test

Type text. Hit Ctrl-d when done
hello

how

are




you

?
Run Code Online (Sandbox Code Playgroud)

我输入密码并确认.太好了.我现在有一个名为"test"的加密文件.

但当我去解密"测试"时,这是输出:

sh decrypt test

gpg: AES256 encrypted data
gpg: encrypted with …
Run Code Online (Sandbox Code Playgroud)

bash gnupg

0
推荐指数
1
解决办法
810
查看次数

如何获得子串到"\ r \n\r \n"

我有以下字符串:

HTTP/1.1 200 OK
Date: Tue, 06 Dec 2011 11:53:22 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.9
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 48
Content-Type: text/html

??(?????I?O????H????????
                          ?4?@??AQ??????t
Run Code Online (Sandbox Code Playgroud)

我想提取"\r\n\r\n",丢弃二进制数据.即:

HTTP/1.1 200 OK
Date: Tue, 06 Dec 2011 11:53:22 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.9
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 48
Content-Type: text/html
Run Code Online (Sandbox Code Playgroud)

如何在C中执行此操作?

c string strstr

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

标签 统计

objective-c ×3

string ×3

iphone ×2

bash ×1

boost ×1

c ×1

c++ ×1

class ×1

compare ×1

gnupg ×1

javascript ×1

jquery ×1

macos ×1

static ×1

strstr ×1

xcode4 ×1