• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Better way to replace a character in a string?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Better way to replace a character in a string?


  • Subject: Re: Better way to replace a character in a string?
  • From: Philippe Martin <email@hidden>
  • Date: Thu, 1 Aug 2002 18:39:40 +0200

At 00:37 -0400 01/08/02, Tom Gray wrote:
>Is there a better way to replace a single character in an NSMutableString
>then this:
>
> // Create an NSString from our character.
> tempString = [NSString stringWithCString:&theCharacter length:1];
>
> // Get the desired location for the character replacement.
> range.location = desiredOffset;
> range.length = 1;
>
> // Replace the character in the terminal string with the new character.
> [myMutableString replaceCharactersInRange:range withString:tempString];

I'd do something like this:

NSArray *temp = [ myString componentsSeparatedByString:searchString ];
return [ temp componentsJoinedByString:replaceString ];

Philippe
--
______________________________________________________________________
Philippe MARTIN (a.k.a. Flip) mailto:email@hidden
http://www.MacrobyteResources.com http://www.Free-Conversant.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Better way to replace a character in a string? (From: Tom Gray <email@hidden>)

  • Prev by Date: Re: Window transformations in Cocoa
  • Next by Date: Re: -LoginHook & -LogoutHook
  • Previous by thread: Better way to replace a character in a string?
  • Next by thread: Re: Better way to replace a character in a string?
  • Index(es):
    • Date
    • Thread