Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
ForExample:
String is---book
I want "book". Because Second time it will change to another thing.So i am not using NSRange.
Any Solution?
Thanks
NSArray *array = [myString componentsSeparatedByString:#"---"];
NSString *bookString = array[1];
Your question is not very clear, but you may need to use this:
NSString* myString = [myPrevString stringByReplacingOccurrencesOfString:#"---" withString:#""];
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I want that every time a user clicks a button the number inside of it increases by 1. Below is the code to do that which works fine. However i want it to be in brackets e.g (1) when they press the button changes to (2) etc. How do i do this?
Thanks
-(IBAction)passButton:(id)sender{
passCounter = passCounter + 1;
passLabel.text = [NSString stringWithFormat:#"%i",passCounter];
}
-(IBAction)passButton:(id)sender{
passCounter++;
passLabel.text = [NSString stringWithFormat:#"(%i)",passCounter];
}
passLabel.text = [NSString stringWithFormat:#"(%i)",passCounter];
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Are there any methods for taking a string and converting all lowercase letters to uppercase?
I was thinking of making a for-loop to run through, check each character, see if it is in range 0061-007A (lowercase letters) and just subtracting 26 (base 16) (converts to the uppercase counterpart) from the unicode code and adding that character back to the string.
But I figured I'd check if there is a simpler method already out there... googled but couldn't find anything... I'm sure I could use a 1x1 UIWebView and load some javascript (that does this) with my string into the UIWebView but there has got to be something already in Objective-C other than the manual approach I first mentioned right?
You do not need a loop - you can use either
NSString *upper = [src uppercaseString];
or
NSString *upper = [src uppercaseStringWithLocale:myLocale];
for targeting a specific locale.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I am creating a check to make sure the user remembers to enter the house number as well as road number in the address.
how would I go about checking to see if a NSString contains 0-9 number characters?
This could be as simple as using rangeOfCharacterFromSet:
NSCharacterSet * set = [NSCharacterSet characterSetWithCharactersInString:#"0123456789"];
if ([aString rangeOfCharacterFromSet:set].location != NSNotFound) {
NSLog(#"This string contains illegal characters");
}
You could also give a look at regular expressions, if you would like to do something fancier with your validation, but in order to just check if a string contains any number, the above is enough.
Have a look at -[NSString (NSRange)rangeOfCharacterFromSet:(NSCharacterSet *)aSet]
and +[NSCharacterSet (id)decimalDigitCharacterSet].
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
Given I have:
int1, int2, int3 = 1, nil, 3
how would I subtract these ints from another variable, only if they weren't nil? I can write something sloppy, but I want a single line process if possible.
another_variable - [int1, int2, int3].compact.sum
othervariable - int1.to_i # will turn nil into 0
You can write something like
ans = int1 && (int2-int1)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I need to convert NSStrings denoting decimal values to hex strings, e.g. a string with value "10" should be converted to string "A", "15" should be converted to "E", "20" should be "14" and so on.
How do I do that?
This should do it:
NSString *hexedString = [NSString stringWithFormat:#"%X",[originalString intValue]];
Note that you might want to do some (non)sense checking.