ios - can not replace all occurrences of quotation (") -


i use below code replace occurrences of quotation (") string:

        nsstring *cluasestext = @"آخرین حقوق کارگر را به‌عنوان \"‌حق سنوات\" به وی ";     cluasestext = [cluasestext                    stringbyreplacingoccurrencesofstring:@"\"" withstring:@"*****"]; 

but code replace 1 of quotations , not replace second one.

i checked both of signs same character wondering why not replacing second one. result after running code is:

آخرین حقوق کارگر را به‌عنوان "‌حق سنوات***** به وی  

while expect:

آخرین حقوق کارگر را به‌عنوان *****حق سنوات***** به وی 

i wondering problem second 1 not replacing?

try below code replace characters want,

nsstring *cluasestext = @"آخرین حقوق کارگر را به‌عنوان \"‌حق سنوات\" به وی ";  nscharacterset *charstobereplace = [nscharacterset charactersetwithcharactersinstring:@"/:.\""];  cluasestext = [[cluasestext componentsseparatedbycharactersinset: charstobereplace] componentsjoinedbystring: @""]; 

hope helps you...

edit , update:

as asked @husein behboodi rad, let me explain going wrong,

the first occurrence of escape char i.e \" in arabic text has different unicode number \u005c\u0022 second \"‌ 1 \u005c\u0022\u200c, if copy , paste first escape character i.e \" , second escape char i.e \"‌ in char unicode converter show different unicode both different.

so in first line of string replacement,

cluasestext = [cluasestext                stringbyreplacingoccurrencesofstring:@"\"" withstring:@"*****"]; 

you have entered normal english language double quote first occurrence of \" matches , stringbyreplacingoccurrencesofstring method replace string has matched exact string (with same unicode). second double quote left or right double quotation mark,

so if have give try, add below code,

nsstring *cluasestext = @"آخرین حقوق کارگر را به‌عنوان \"‌حق سنوات\" به وی ";  cluasestext = [cluasestext                stringbyreplacingoccurrencesofstring:@"\"" withstring:@"*****"]; cluasestext = [cluasestext                stringbyreplacingoccurrencesofstring:@"\"‌" withstring:@"*****"]; 

and output

آخرین حقوق کارگر را به‌عنوان *****حق سنوات***** به وی 

so how come charactersetwithcharactersinstring working question, i'm not expert of character set imho, charactersetwithcharactersinstring method replaces occurrence string without considering unicode of strings partially same whereas stringbyreplacingoccurrencesofstring withstring replaces string exact unicode matching string.

this explain now.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -