ios7 - I want to add a space in between a string in objective c -
- (ibaction)addspace:(id)sender { //here nospce textbox in enter value nsstring *one=self.nospace.text; if (one.length==4) //if length of string equal 4 should put whitespace //in between string. { nsstring *blank=@" "; nsstring *two=[blank. stringbyappendingstring:one,index(2)]; nsstring *new=two; //here withspace textbox in want show expected result self.withspace.text=new; } //this not work me
nsstring *two=[blank. stringbyappendingstring:one,index(2)];
there's extraneous .
after blank
in method call. remove , index(2)
, code should work better.
your code improved using mutable string. use -insertstring:atindex:
, avoid need intermediate strings.
update: should change name of new
variable. new
name of method in nsobject, , reserved word in c++. using variable name should work, it's bound lead confusion in future.
Comments
Post a Comment