I have string something like @"goodhouse=30&app=60&val=30askldkla"
How can I found the value 30 between house= and &, and change it on 50?
Asked
Active
Viewed 67 times
-2

Cœur
- 37,241
- 25
- 195
- 267

user2398911
- 96
- 1
- 14
-
i have tried `[str replaceOccurrencesOfString:@"30" withString:@"60" options:NSCaseInsensitiveSearch range:NSMakeRange(0, str.length)];` but it doesn't good if there are the same value – user2398911 May 27 '13 at 12:58
3 Answers
4
You can find a range between house= and & string using NSRange
. And if range exists, then change the string which you want.

iDeveloper
- 223
- 2
- 5
1
if ([yourString rangeOfString:@"30"].location==NSNotFound)
{
yourString = [yourString stringByReplaceOccurenceOfString:@"30" withString@"60"];
}

iDeveloper
- 223
- 2
- 5
0
try like this,
string=@"30";
str=[str stringByReplaceOccurenceOfString:string withString@"50"];
EDIT:- try like this,
NSString *test = [dateandtime stringByReplacingCharactersInRange:NSMakeRange(10,2) withString:@"50"];

Balu
- 8,470
- 2
- 24
- 41
-
i try it but the problem if there are two string with 30. it make 50 for all of them but i need only for one – user2398911 May 27 '13 at 12:59
-
i wrote about it upper that using nsrange is bad because if string will be dynamic i all times need to count the range – user2398911 May 27 '13 at 13:06
-
-
if other than 30 is placed in between those then wt you want to do at that time? – Balu May 27 '13 at 13:11
-
30 will be static. so i need to found the value between house= and &app and change it. – user2398911 May 27 '13 at 13:21