我有3个NSString
和1个NSArray值,我尝试将所有字符串转换为一个:
string01 = [string01 stringByAppendingString:[numbersValue objectAtIndex:Value1 -1]];
string03 = [string02 stringByAppendingString:[numbersValue objectAtIndex:Value2 -1]];
string03 = [string03 stringByAppendingString:[numbersValue objectAtIndex:Value3 -1]];
//here i will to convert value of striing01 in to string02 and string02 in to string03 than take last string in my UITextView
resulteString = [resulteString stringByAppendingString:<what i can write here?>];
[myTextView setText:resulteString];
就像一个Enigma机器,例如,如果你想一个键盘并按下A,
A pass inside a string01 and become B,
B pass inside a string02 and become C,
C pass inside string03 and become D
in my text view i need to see only D
答案 0 :(得分:1)
如果resulteString是NSString类的对象 然后使用
resultString = [NSString stringWithFormat:@"%@%@%@%@", resultString,string01, string02, string03];
否则,如果resulteString是NSMutableString类的对象
resulteString = [resulteString stringByAppendingFormat:@"%@%@%@", string01, string02, string03];
可以帮到你。
答案 1 :(得分:1)
我明白你的意思。如果你想通过移动加密你的字符串,你需要一个像这样的方法:
//Edit this method how you want to use this is just an example
-(NSString *) encodeString:(NSString *) realString{
NSArray *alphabet=[NSArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"R",@"S",@"T",@"U",@"V",@"W",@"Y",@"Z",nil];
int index=[alphabet indexOfObject:realString];
index ++;
NSString *resultString=[alphabet objectAtIndex:index];
return resultString;
}
你需要逐个角色。使用UITextField的委托 每次你点击键盘,调用这个方法,你会得到新的字符串。并且每次都将此字符串附加到另一个字符串。
希望它有效。
答案 2 :(得分:0)
使用此功能
[NSArray componentsJoinedByString]
答案 3 :(得分:0)
您可以使用如下
First write
in YourController.h file NSString *newString;
// Add below line in viewDidLoad
newString = @"";
// In Your function
// A pressed from keyboard
NSString *str1 = @"Newly pressed Keyboard Key";
// Add New Pressed key with existing one
newString = [NSString stringWithFormat:@"%@ %@",newString,str1];
这样你可以在一个函数中添加它,并在用户从键盘按任意键时调用。
希望这会对你有所帮助。