Convert decimal NSString to a hex string [closed] - ios

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.

Related

ruby, regex extract price from string [closed]

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
In ruby i have a string like this:
str= 43,69 €
Is possible with a regex obtain 43,69 ?
I have tried with:
/\d+(?:\.\d+)?/
but the output is incorrect: 43.0
This should work
/\d+(?:[.,]\d+)?/
The [.,] part matches decimal separator for a dot or a comma. If you are sure thet decimal separator will be a comma, you can use this:
/\d+(?:,\d+)?/

Make lowercase letters in a string uppercase [closed]

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.

What is the best way to check if a string contains any numbers? [closed]

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].

Subtract Variable if Present in Ruby [closed]

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)

how to extract string between two characters in iOS in NSMutablestring? [closed]

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:#""];

Resources