Xcode how trim a string with special character $ - trim

I've a string with this kind of value /finocchi$FINOCCHamelo
Now I need a new string with only this part of the word FINOCCHamelo
I've try this:
NSString * newString = [item.label stringByReplacingOccurrencesOfString:#"$" withString:#""];
But it's not right becouse change the $ with blank char.
I need to filter the string afther $
How Can I do?

Assuming in all the case you have only one $ in your string and you need the value after $.
NSArray *brokenStrings = [item.label componentsSeparatedByString:#"$"];
NSString *filteredString = [brokenStrings objectAtIndex:1];
There are a lot more ways to do this:
You can opt any one from these methods, or dozen other methods are available in NSString.
– componentsSeparatedByString:
– substringFromIndex:
- rangeOfString:
– stringByTrimmingCharactersInSet:

Related

How do I delete characters in a string up to a certain point in classic asp?

I have a string that at any point may or may not contain one or more / characters. I'd like to be able to create a new string based on this string. The new string would include every character after the very last / in the original string.
Sounds like you're wanting the file name from a URL. In any case, it's the same function. The key is using the InStrRev function to find the first / char, but starting from the right. Here's the function:
Function GetFilename(URL)
Dim I
I = InStrRev(URL, "/")
If I > 0 Then
GetFilename = Mid(URL, I + 1)
Else
GetFilename = URL
End If
End Function
Split it up into parts and get the last part:
a = split("my/string/thing", "/")
wscript.echo a(ubound(a))
note: Not safe when the string is empty.

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 convert string to int?

How to convert string to int?I know convert.ToInt32 is used.But it fail.Error is input string is not in proper format.
String s1 = "12.00"
I love the assumption that the decimal separator always is a dot (.). You'd better use the InvariantCulture, which contains a NumberFormat that explicitly specifies the dot as a decimal separator:
Convert.ToInt32(Convert.ToDouble("12.00", CultureInfo.InvariantCulture));
To clarify: half the world uses the dot, the other half a comma. When I run this on a PC with a Dutch culture and do not specify a CultureInfo, it takes the system default (comma) and returns 1200, ignoring the dot.
While it does not directly affect your problem, it is something that can't be stressed enough.
error is because string is "12.00"
first convert string to double than in int
int a = Convert.ToInt32(Convert.ToDouble("12.00"));
or
IF you just want integer part of it than
string s= "12.00";
string[] words = s.Split('.');
int a = Convert.ToInt32(words[0]);
Also check already answered threads on SO : C# Convert String Decimal to Int
"12.00" is a decimal number, not an integer. Integers don't have fractional portions. Use Convert.ToDouble or similar to get a floating-point number, or trim off the decimal part of the string (the . and what follows) prior to calling Convert.ToInt32.
The string "12.00" is a double/decimal value. Use Double.Parse() or Double.TryParse() or Convert.ToDouble().

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.

How to insert complex strings into Actionscript?

How to insert complex strings into Actionscript?
So I have a string
-vvv -I rc w:// v dv s="60x40" --ut="#scode{vcode=FV1,acode=p3,ab=128,ch=2,rate=4400}:dup{dt=st{ac=http{mime=v/x-flv},mux=mpeg{v},dt=:80/sm.fv}}"
How to insert it into code like
public var SuperPuperComplexString:String = new String();
SuperPuperComplexString = TO_THAT_COMPLEX_STRING;
That string has so many problems like some cart of it can happen to be like regexp BUTI DO NOT want it to be parsed as any kind of reg exp - I need It AS IT IS!)
How to put that strange string into variable (put it not inputing it thru UI - hardcode it into AS code)?
SInce the only problem characters in your string are the double quotes ( " " ), just enclose your String in single quotes ( ' ' ). That will solve any problems.
It also depends on how you are loading that string into your code, as well.
You could even go so far as to encase that String in XML CDATA to ensure it's all delimited for when you want to use it.
var myString:XML = new XML();
myString = "<string><![CDATA[-vvv -I rc w:// v dv s="60x40" --ut="#scode{vcode=FV1,acode=p3,ab=128,ch=2,rate=4400}:dup{dt=st{ac=http{mime=v/x-flv},mux=mpeg{v},dt=:80/sm.fv}}"]]></string>"
Then, you can access it as a string from anywhere by just referencing myString.
var myString:String = '-vvv -I rc w:// v dv s="60x40" --ut="#scode{vcode=FV1,acode=p3,ab=128,ch=2,rate=4400}:dup{dt=st{ac=http{mime=v/x-flv},mux=mpeg{v},dt=:80/sm.fv}}"'
Not sure where your problem is..

Resources