I currently have several arrays of strings which join together into one array of strings for a search. #"%# | %# | %# | %# | %# | %#". Now I am trying to separate the contents of the large array of strings, #"%#", back into the original six strings. Is there any way I can do this. Yes it sounds redundant but it is necessary at this point of development.
Edit: For clarification, I am using six parallel arrays and inserting each corresponding value between the pipes and converting it into a combined array of strings. I want to separate
"Word A | Word B | Word C | Word D | Word E | Word F", into
NSString A = "Word A";
NSString B = "Word B";
etc.
To separate this string you can use:
NSArray *array = [yourStrngToSeparate componentsSeparatedByString:#" | "];
If you want to put it back to string you don't have to use stringWithFormat, you can do:
NSString *string = [array componentsJoinedByString:#" | "];
Related
What is the meaning of {2,4} when validating an email with the following regular expression:
NSString *emailRegEx = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailRegEx];
It mean words length is minimum 2 and maximum 4 and it takes Capital A to Z and small a to z characters..
{2,4} means the string has minimum 2 characters and maximum 4 characters (The length of string should be greater than or equal to 2 and less than or equal to 4).
For example: In email ids and after dot, .com,.in, .uk so on...
In above regular expression, {2,4} means you can take occurrence of [A-Za-z] between 2 to 4 inclusive.
Ref
http://www.regular-expressions.info/reference.html
http://www.regextester.com/
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I concatenate strings in Objective-C?
Hello everyone I am new to Objc, I want to concatenate strings of the Integer value with string value.
Here is my code:
[runtime setText:[NSString stringWithFormat:#"%#",self.movie.runtime]];
The result will be: 120
The result that I wish to concatenate string is: 120 Minutes.
Please share me about this.
Thanks
I guess, you want this
[runtime setText:[NSString stringWithFormat:#"%# Minutes",self.movie.runtime]];
while concatenating would be:
NSString *newString = [aString stringByAppendingString:anotherString];
for immutable NSStrings
and
[aMuteableString appendString:anotherString];
for NSMutableStrings
How can i format my NSString to be something like
1 Item1 7.00 0% 7.00
1 Item2 6.00 0% 6.00
i'm getting the string from html it is in table format. Any ideas?
You can use IEEE printf flags to specify field widths (it's in the iOS library documentation). That means that if you have the content of the table cells as separate values or objects, you can create your fixed-space string using NSString's stringWithFormat: method.
I think, it solves your problem?
NSString *str = [NSString stringWithFormat:#"%i \t %# \t %.2f %%%i %.2f",1,#"Item1",7.00,0,6.00];
NSLog(#"%#", str);
i found this
Is it possible to use format strings to align NSStrings like numbers can be?
I have a similar task but the opposite format.
TOTAL: 2
SUBTOTAL: 6.00
TAX: 0%
CASH: 12.00
my code is this
NSString* item [NSString stringWithFormat:#"%-10s %#", #"TOTAL",#"2"];
Yet outcome is this
TOTAL: 2
SUBTOTAL: 6.00
UPDATE
I got it to work with this code.
NSString* item [NSString stringWithFormat:#"%12s %7s", [total UTF8String],[amount UTF8String]];
UPDATE QUESTION
What if the text is too long?
THIS TEXT IS TOO LONG
I want it to be
THIS TEXT
IS TOO LONG
I have 2 NSArray's that are holding values...
For example NSArray 1 has values 1 2 4 in it
and NSArray 2 has values 1 2 4 5 6 in it.
How can I write code to compare these 2 arrays to get the following information...
Count the values that are the same (so in this case 3) and count the values that are not the same (in this case 2).
I am simply populating the arrays like this:
NSString *s = #"1,2,4";
NSArray *numbers = [s componentsSeparatedByString:#","];
where *s is actually getting the text from a UITextField. If sorting mattering in comparing can you show me code to sort to make sure the user doesnt put the numbers in order?
If you are fine with sets instead of arrays, you can use NSMutableSet instead of NSArray. NSMutableSet has nice methods like intersectSet: and minusSet:
I would probably use the following method of the NSArray class:
enumerateObjectsUsingBlock.
and code the block testing for membership in the other array with the method:
indexOfObjectIdenticalTo.
If this isn't clear to you let me know.