-2

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?

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 Answers3

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