• 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
special characters are destroyed when copying a string character by character
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

special characters are destroyed when copying a string character by character


  • Subject: special characters are destroyed when copying a string character by character
  • From: Horst Jäger <email@hidden>
  • Date: Tue, 05 Apr 2011 17:55:49 +0200

Hi,

I have noticed that special characters are destoryed when they are copied one by one from one string into another. Listed below is some demo code (demo.h, Demo.m) which yields the console log also listed below (Demo.log).

It states that the String containig no special characters is copied properly while the other is not.

Any idea why?

Thanks in advance

Horst



:::::::::::::::::::::::::::::::::::: Demo.log ::::::::::::::::::::::::::::::::::::

2011-04-05 17:47:24.280 Demo[8890:207] Wurst Wurst 1
2011-04-05 17:47:24.281 Demo[8890:207] Käse K‰se 0

:::::::::::::::::::::::::::::::::::: /Demo.log ::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::: Demo.h ::::::::::::::::::::::::::::::::::::

@interface Demo : NSObject

+(NSString*)copyUnicharByUnicharString:(NSString*)src;

+(void)demo;

@end

:::::::::::::::::::::::::::::::::::: /Demo.h ::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::: Demo.m ::::::::::::::::::::::::::::::::::::

#import "Demo.h"


@implementation Demo

+(NSString*)copyUnicharByUnicharString:(NSString*)src{
	NSMutableString* dst = [NSMutableString string];
	NSUInteger length = [src length];
	for(NSUInteger index = 0; index < length; ++index){
		unichar chr = [src characterAtIndex:index];
		[dst appendFormat:@"%c", chr];
	}
	return dst;
}

+(void)demo{

	NSString* sausageString = @"Wurst"; // Wurst is the German word for sausage
	NSString* cheeseString  = @"Käse" ; // Käse  is the German word for cheese

	NSString* sausageStringCopy = [self copyUnicharByUnicharString:sausageString];
	NSString* cheeseStringCopy  = [self copyUnicharByUnicharString:cheeseString ];

	BOOL sausageStringIsEqualToSausageStringCopy = [sausageString isEqualToString:sausageStringCopy];
	BOOL cheeseStringIsEqualToCheeseStringCopy   = [cheeseString  isEqualToString:cheeseStringCopy ];

	NSLog(@"%@ %@ %d", sausageString, sausageStringCopy, sausageStringIsEqualToSausageStringCopy);
	NSLog(@"%@ %@ %d", cheeseString , cheeseStringCopy , cheeseStringIsEqualToCheeseStringCopy  );

}

@end

:::::::::::::::::::::::::::::::::::: Demo.m ::::::::::::::::::::::::::::::::::::












--
Horst Jäger		email@hidden
Medienkonzepte	http://www.medienkonzepte.de/
Schaafenstr. 25, 50676 Köln, Germany
Tel +49 221 93187017  / Fax +49 221 93187029

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: special characters are destroyed when copying a string character by character
      • From: Kyle Sluder <email@hidden>
    • Re: special characters are destroyed when copying a string character by character
      • From: Sherm Pendley <email@hidden>
  • Prev by Date: Re: Odd NSCache Eviction Behaviour
  • Next by Date: Re: special characters are destroyed when copying a string character by character
  • Previous by thread: Re: Dynamically Loading Code and Core Data Non-Standard Persistent Attributes
  • Next by thread: Re: special characters are destroyed when copying a string character by character
  • Index(es):
    • Date
    • Thread