How fetch text from NSString - nsstring

I have NSString *searchResult with text (cityId, name, lat, lon, country) like this :
6058560 London 42.983391 -81.233040 CA
How to fetch this values from string (need separated objects).
Thanks.

Look at using componentsSeparatedByCharactersInSet: with the white space character set.

Related

ASP Classic Method to Extract City from Address String

I am looking for a method to extract only the city from an address string in ASP Classic, is there a way I can do this, or resources i can read?
eg: C. del Esperanto, 17B, 03503 Benidorm, Alicante, Spain.
I want just Benidorm, the address strings will always be in the same format
Split on comma, then on the 3rd one (2 in the array), split on space, and take the second (1 in array)
Give this a try
addressSplit1 = Split(address, ",")
addressSplit2 = Split(addressSplit1(2), " ")
city = addressSplit2(1)

I need to convert trackbar value to hex bytes and display it on text box

In c# i have a trackbar with range of 0-254.
I want to convert each digit to hex byte, meaning that 250 will be "32-35-30"
and display that in a text box
how can i do that?
I dont have any code for example
It is a simple task:
string s = "250";
byte[] array = System.Text.Encoding.ASCII.GetBytes(s);
string s2=BitConverter.ToString(array);
Now s2 has the desired output.

How to convert emojis from to unicode in Xamarin.forms?

I have Xamarin.Forms project. I have textbox in that and have a button which get text from textbox and pass it to API to store. Now the point is when user select any emojis from keyboard, I want to get unicode character of the emojis. Currently I am getting emojis it self when I check Text property of it.
I want to get Unicode rather emoji as given in NewTextValue from Text property.
This post is same but I don't understand how the guy has managed. POST
Please suggest.
After some google, I have tried with following.
string res = BitConverter.ToString(Encoding.BigEndianUnicode.GetBytes(str)).Replace("-", "");
This is result res = D83DDE00
I don't know above code is unicode or not.
How can I convert back to original emoji or is there any other way to convert in unicode?
We need to manually convert it back. Insert "-" every two characters:
var convertStr = string.Join("-", Regex.Matches(res, #"..").Cast<Match>().ToList());
String[] tempArr = convertStr.Split('-');
byte[] decBytes = new byte[tempArr.Length];
for (int i = 0; i < tempArr.Length; i++)
{
decBytes[i] = Convert.ToByte(tempArr[i], 16);
}
String str = Encoding.BigEndianUnicode.GetString(decBytes);
Moreover in my test, Encoding.UTF32.GetBytes() may be closer to emoji code. You can test it with \U0001F600, this is a smile image. After converting with utf32, the bytes just change its order.

how do i delete characters in a string/text of a textbox?

I have an asp.net 4 textbox control that has it's text being dynamically populated by some java script. A Google Maps call to be exact. It's giving me mileage from 1 point to another. When the text displays, it shows " 234 mi" I need to get rid of the "mi" part of this text because the text is being converted to an Int32 Updating a table in my DB.
Basically I can only have an INT. Nothing else in the text box. How do I get rid of the "mi" at the end of the text?
Thanks
C#
EB
On the postback, before you save it you could:
var saveValue = Int32.Parse(tbTarget.Text.Replace("mi", string.Empty).Trim());
If your working with a variable length of chars (say someone enters miles instead) then your must do a foreach against the string (an array of char) and check isnumeric on each char.
A simple String.Substring works also:
String leftPart = TxtMileAge.Text.Substring(0, txt.IndexOf(' '));
int mileAge = int.Parse(leftPart);
This retrieves the part of the String in the range of 0 - indexOfWhiteSpace and converts it to an int
Edit: Since the value can have decimal places (as you've commented), you need to parse it to double, round it and then cast it to int:
var txtEstDistance = new TextBox() { Text = "40.2 mi" };
String leftPart = txtEstDistance.Text.Substring(0, txtEstDistance.Text.IndexOf(' '));
double distanceMiles = double.Parse(leftPart, System.Globalization.CultureInfo.InvariantCulture);
int oDdstanceMiles = (int)Math.Round(distanceMiles, MidpointRounding.AwayFromZero);

How to get string from a long string?

I have a string like this:
NSString *aString =
[NSString stringWithFormat:"********************Documents/image%#.jpg",aNumber];
I want to get "Documents/image%#.jpg" out of the string?
What can I do? I want to use "substringFromIndex" but I don't know the index.
You can use rangeOfString to find the index of "Documents...".
NSString class reference
And then use that with 'substringFromIndex' to get the substring you want.
For example:
[astring substringFromIndex:[aString rangeOfString:#"Documents"].location]
You should add error checking to make sure that the range returned by the 'rangeOfString' method is good.

Resources