views:

92

answers:

5

i have a sting in which i want to replace all characters(except special characters) by X.. i mean if i have a string str= mac,iphone & ipad are products of apple

theis should be converted to

str= XXX,XXXXXX & XXXX XXX XXXXXXXX XX XXXXX

i know this can be done by finding all special characters and note their position and then replace all other characters except these special characters but there are so many special characters should i check them one by one ? or is there any other method to identify them

please help

A: 
[Nsstring stringByReplacingOccurrencesOfString:@"" withString:@"X"];

from this you can replace string according to my knowledge

GhostRider
it does not works good for my problem this is not for all characters from a-z
Ranjeet Sajwan
just take one array and store all in array and then compare each array object if it is alphabet then change it into X other wise save as it in append string
GhostRider
actually the main problem is ..how to check that current character is alphabet
Ranjeet Sajwan
A: 

I'd use a regular expression. Check out the documentation for NSRegularExpression

Nimrod
+1  A: 

NSString *str=@"mac,iphone & ipad";

for(int i=0;i<[str length];i++)
{
    int str1=(int)[str characterAtIndex:i];
    NSString *temp=[NSString stringWithFormat:@"%C",str1];

    if(str1 >96 && str1 <123  || str1 >64 && str1 <91)

        str = [str stringByReplacingOccurrencesOfString:temp withString:@"X"];
}

Hope this helps...This will replace all characters either in upper/lower case

sherry
good work sherry....it worked and i become to know some special....moves....voted and acceptedwill you please answer my another question herehttp://stackoverflow.com/questions/3869790/change-name-of-iphone-project
Ranjeet Sajwan
+1  A: 

NSString *s = @"foo/bar:baz.foo"; NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"/:."]; s = [[s componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""]; NSLog(@"%@", s);

Try this it is more useful when the above answered ways don't replaces the charachters.

Please vote me up if it helps you. I am new to iphone development.

sabby
+1---ya....But too late....to accept....sherry was already accepted...don't mind....be ahead next time
Ranjeet Sajwan
chandigarh....where ?i also work here.....i want to talk to you..
Ranjeet Sajwan
Well I work in mohali and what about you.....
sabby
sorry for late .....i work in sector 44 chd.....what is your org...name
Ranjeet Sajwan
interworld and your org name whats that?
sabby
emobilityexpertz.....from how many times you are working here?
Ranjeet Sajwan
A: 
  • (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if(TextFound) { NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"/
    "]; string = [[string componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];

        TextStr = [TextStr stringByAppendingString:string];
    }
    

    }

As i did it in my parsing, it was showing linebreak character in the text.I tried the way stringbyrplacingoccurance of string ,but nothing happened ,so finally it worked.

hope it will help you

sabby