NSString's hash method and back? [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 9 years ago.
Improve this question
Once I use [NSString hash] and get a NSUInteger, is there any way I can use that NSUInteger and turn it back into the original NSString? Apple doesn't really say anything about the implementation of the hash method in the docs.
FYI: I'm trying to store identifierForVendor as a NSNumber (specifically in either the major or minor property of a CLBeacon).

No. The hash is 32 or 64 bits, a string can be much longer, so it is inherently lossy, and the hash values are not unique (the same hash corresponds to multiple strings).

Actually, hash is not supposed to be de-coded. You may want to read something like http://en.wikipedia.org/wiki/Hash_function
Apple says "If two string objects are equal (as determined by the isEqualToString: method), they must have the same hash value". That's all you can get.

If you want to store it for later comparisons, then you should hash the both NSStrings & compare the resulting NSUIntegers

Related

How to generate the same random sequence from a given seed in Delphi [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
I am wanting to generate the same random sequence (of numbers or characters) based on a given "seed" value.
Using the standard Randomize function does not seem to have such an option.
For example in C# you can initialize the Random function with a seed value (Random seed c#).
How can I achieve something similar in Delphi?
You only need to assign a particular value to the RandSeed global variable.
Actually, I'm almost surprised you asked, because you clearly know of the Randomize function, the documentation for which states the following:
The random number generator should be initialized by making a call to Randomize, or by assigning a value to RandSeed.
The question did not mention thread safety as a requirement, but the OP specified that in comments.
In general, pseudorandom number generators have internal state, in order to calculate the next number. So they cannot be assumed to be thread-safe, and require an instance per thread.
For encapsulated thread-safe random numbers, one alternative is to use a suitably good hash function, such as xxHash, and pass it a seed and a counter that you increment after each call in the thread.
There is a Delphi implementation of xxHash here:
https://github.com/Xor-el/xxHashPascal
For general use, it's easy to make several versions in 1, 2 or 3 dimensions as needed, and return either floating point in 0..1 or integers in a range.

How to parse string to call array and its array contents [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to parse string and call array using valueForKeyPath:
ex:
NSArray *myArray = #[1,2,3,4,5,6,7,8];
I have a string's as below
myArray[], myArray[3],myArray[1..3]
when i evaluate these strings i want output like below
evaluate(#"myArray[]")
output:#[1,2,3,4,5,6,7,8]
evaluate(#"myArray[3]")
output:4
evaluate(#"myArray[1..3]")
output:#[2,3,4]
I am already using custom function using valueForKeyPath: for calling methods and functions. I am stuck with array and parameters
You have shown nothing you have attempted, so it is unclear what your problem is – you appear to know about things (valueForKeyPath:, regular expressions) you could build a solution from.
Here is an outline of a solution:
Your strings all appear to be of one of three forms: an array name followed by zero, one or two integers in square brackets. You can break this up to extract the one to three important parts using (at least) NSRegularExpression or NSScanner. If you pick NSRegularExpression just be careful writing the pattern as [, ], and . are special characters and will need appropriate escaping – just read the documentation.
Once you have your three parts you can obtain the value of the array using valueForKey: assuming it is either a property or an instance variable.
If you have matched/scanned one or two indexes then you can use the methods of NSArray to obtain the object(s), you might find NSIndexSet useful here.
That's it. If you try to do this and get stuck edit your question showing what you have tried, state what is broken, and ask for help; someone will probably be able to help further.
HTH

How to insert charactor like "don't" in Sqlite in ios [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
I am inserting some keyword like Don't , has'nt in Sqlite which is not inserted.any one have idea about it.
Use ' as escape character and insert it like this:
dont''t
Documentation:
A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal
In case you are using an API to connect with Sqlite, instead of manipulating the original string a better approach would be to use sqlite3_bind_text() function to bind a value to a ? placeholder in the SQL. Thanks to #Rob for pointing this out.

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.

A calculator app on iOS [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
Can anyone please explain the difference between this
[display setText:[[display text] stringByAppendingString:digit ]];
and this
[display setText:digit];
The code is rather clear. But if you don't understand:
Here [display setText:[[display text] stringByAppendingString:digit ]]; a new digit will be added to the digits currently displaying on the screen. This BOOL value userIsInTheMiddleOfTypingANumber is extremely straightforward - it is said that there are always digits on the screen and a new digit must be added to them. This method stringByAppendingString returns a new string made by appending a given digit to the currently displayed digits in the UITextField.
And here [display setText:digit]; all the text which are displayed in the UITextField will be overwritten with a new digit value. But as I suppose it is used when there are no digits on the screen and we need to write the first one.I don't know what is using for displaying digits in that app. But if it is UITextField then using setText is a bad idea - it is a deprecated method. You should use text property instead.
This is an extremely simple code which you need to understand yourself. So my advice you to read some introductory books on CocoaTouch and iOS with simple examples there are plenty of them: http://www.amazon.com/Beginning-iOS-Development-Exploring-SDK/dp/1430245123/ref=pd_sim_b_8 . And don't forget to use official documentation.

Resources