I have a string with value "€100,000,000". I want to remove the '€'  and ',' at the same time. I am try to use [NSCharacterSet symbolSet] but this method only removes the '€' without removing the ','.
            Asked
            
        
        
            Active
            
        
            Viewed 131 times
        
    0
            
            
         
    
    
        Yuvaraj M
        
- 340
- 2
- 13
- 
                    Can you show how you are doing that? – Nitish Sep 05 '12 at 12:17
- 
                    your code is working fine for me. 2012-09-05 19:20:53.950 test[17026:a0f] 100000000 – Parag Bafna Sep 05 '12 at 13:51
5 Answers
2
            
            
        Use this:
string = [string stringByReplacingOccurrencesOfString:@"€" withString:@""];
string = [string stringByReplacingOccurrencesOfString:@"," withString:@""];
 
    
    
        David Manpearl
        
- 12,362
- 8
- 55
- 72
 
    
    
        Andrey Chernukha
        
- 21,488
- 17
- 97
- 161
2
            You can try:
-(NSString*)cleanString:(NSString*)str
    NSString *string = [NSString stringWithString:str];
    NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:@"€,"];
    string = [string stringByTrimmingCharactersInSet:charSet];
    return string;
}
 
    
    
        woz
        
- 10,888
- 3
- 34
- 64
 
    
    
        janusfidel
        
- 8,036
- 4
- 30
- 53
1
            
            
        Best solution is Remove all but numbers from NSString answer.
Alternative for fixed cleaning in string is:
string = [[string stringByReplacingOccurencesOfString:@"€" withString:@""] stringByReplacingOccurencesOfString:@"," withString:@""];
 
    
    
        Community
        
- 1
- 1
 
    
    
        Paresh Navadiya
        
- 38,095
- 11
- 81
- 132
1
            
            
        string = [string stringByReplacingOccurrencesOfString:@"€" withString:@""]; 
where string contains "€100,000,000"
 
    
    
        Zoltan Toth
        
- 46,981
- 12
- 120
- 134
 
    
    
        user1573162
        
- 47
- 7
0
            
            
        Commas are not symbols.  It's part of the [NSCharacterSet punctuationCharacterSet].  But if you use that set it will remove the decimal place holder (period).
You will just have to do two operation to get the result you want.
- Use [NSCharacterSet symbolSet]which will take care of all symbols for currency.
- Use the stringByReplacingOccurencesOfStrinto remove only the","
 
    
    
        Black Frog
        
- 11,595
- 1
- 35
- 66