Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the index of a character in a string

I have a string NSString *Original=@"88) 12-sep-2012"; or Original=@"8) blablabla";

I want to print only the characters before the ")" so how to find the index of the character ")". or how could i do it?

Thanks in advance.

like image 322
fadd Avatar asked Sep 12 '12 09:09

fadd


People also ask

How do you get the index of a character in a string?

To get the index of a character in a string, you use the indexOf() method, passing it the specific character as a parameter. This method returns the index of the first occurrence of the character or -1 if the character is not found.

How do you find the index of a particular character in a string in JavaScript?

JavaScript String indexOf() The indexOf() method returns the position of the first occurrence of a value in a string. The indexOf() method returns -1 if the value is not found. The indexOf() method is case sensitive.

How do I find a specific character in a string Java?

You can search for a particular letter in a string using the indexOf() method of the String class. This method which returns a position index of a word within the string if found. Otherwise it returns -1.


1 Answers

U can find index of the character ")" like this:

NSString *Original=@"88) 12-sep-2012";
NSRange range = [Original rangeOfString:@")"];
if(range.location != NSNotFound)
{
 NSString *result = [Original substringWithRange:NSMakeRange(0, range.location)];
}
like image 173
Paresh Navadiya Avatar answered Oct 15 '22 12:10

Paresh Navadiya