Search Results

Search found 2356 results on 95 pages for 'nsstring'.

Page 4/95 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How do I convert an NSMutableString to NSString when using Frameworks?

    - by BWHazel
    I have written an Objective-C framework which builds some HTML code with NSMutableString which returns the value as an NSString. I have declared an NSString and NSMutableString in the inteface .h file: NSString *_outputLanguage; // Tests language output NSMutableString *outputBuilder; NSString *output; This is a sample from the framework implementation .m code (I cannot print the actual code as it is proprietary): -(NSString*)doThis:(NSString*)aString num:(int)aNumber { if ([outputBuilder length] != 0) { [outputBuilder setString:@""]; } if ([_outputLanguage isEqualToString:@"html"]) { [outputBuilder appendString:@"Some Text..."]; [outputBuilder appendString:aString]; [outputBuilder appendString:[NSString stringWithFormat:@"%d", aNumber]]; } else if ([_outputLanguage isEqualToString:@"xml"]) { [outputBuilder appendString:@"Etc..."]; } else { [outputBuilder appendString:@""]; } output = outputBuilder; return output; } When I wrote a text program, NSLog simply printed out "(null)". The code I wrote there was: TheClass *instance = [[TheClass alloc] init]; NSString *testString = [instance doThis:@"This String" num:20]; NSLog(@"%@", testString); [instance release]; I hope this is enough information!

    Read the article

  • Should I release NSString before assigning a new value to it?

    - by Elliot Chen
    Hi, Please give me some suggestions about how to change a NSString variable. At my class, I set a member var: NSString *m_movieName; ... @property(nonatomic, retain) NSString *m_movieName; At viewDidLoad method, I assign a default name to this var: -(void)viewDidLoad{ NSString *s1 = [[NSString alloc] initWithFormat:@"Forrest Gump"]; self.m_movieName = s1; ... [s1 release]; [super viewDidLoad] } At some function, I want to give a new name to this var, so I did like: -(void)SomeFunc{ NSString *s2 = [[NSString alloc] initWithFormat:@"Brave Heart"]; //[self.movieName release]; // ??????? Should perform here? self.m_moiveName = s2; [s2 release]; } I know, NSString* var is just a pointer to an allocated memory block, and 'assign' operation will increment this memory block's using count. For my situation, should I release m_movieName before assigning a value to it? If I do not release it (via [self.movieName release]), when and where will the previous block be released? Thanks for your help very much!

    Read the article

  • NSDictionary: convert NSString keys to lowercase to search a string on them

    - by VansFannel
    Hello. I'm developing an iPhone application. I use a NSDictionary to store city's names as key, and population as value. I want to search the keys using lowercase. I've using this: NSDictionary *dict; [dict objectForKey:[[city stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] lowercaseString]]; But, it doesn't work. I know, I can do a for, convert keys to lowercase and compare with city. Is there any other way to do that? Maybe, with a NSDictionary method. UPDATE The NSDictionary is loaded from a property list. Thank you.

    Read the article

  • How can I extract a URL from a sentence that is in a NSString?

    - by 0SX
    What I'm trying to accomplish is as follows. I have a NSString with a sentence that has a URL within the sentience. I'm needing to be able to grab the URL that is presented within any sentence that is within a NSString so for example: Let's say I had this NSString NSString *someString = @"This is a sample of a http://abc.com/efg.php?EFAei687e3EsA sentence with a URL within it."; I need to be able to extract http://abc.com/efg.php?EFAei687e3EsA from within that NSString. This NSString isn't static and will be changing structure and the url will not necessarily be in the same spot of the sentence. I've tried to look into the three20 code but it makes no sense to me. How else can this be done? Thanks for help.

    Read the article

  • how can I translate a NSString to NSData? And the data has the same content as the string

    - by someonemaybe
    NSString * theString=@"e88d"; NSData * data; // something I should implement NSLog(@"%@", theString); NSLog(@"%@",[data description]); I want the results of the two printings are the same. AES encryption and decryption: (1).The server: if the plaintext is :@"abcd"; the AES encrypted data(NSData data type) is :"d882830c dc892036 4345839f 13c7516a"; (2).in my local app, my code is : NSData*data=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://..."]]; NSString * mystring= [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; However, to decrypt data successfully, I must got a data(NSData date type) which equals to "d882830c dc892036 4345839f 13c7516a".But it is the mystring (NSString data type) not the data(NSData data type) that equals to the right value. the encryption and decryption function both need a data(NSData data type) as input datas. (NSData*)AES128EncryptWithKey:(NSString*)key; (NSData*)AES128DecryptWithKey:(NSString*)key;

    Read the article

  • Comparing an [NSURL path] to an NSString doesn't work

    - by Koning Baard XIV
    I have this code: NSLog([url path]); if([url path] == @"/connect/login_success.html") { NSLog("IT WORKZ"); } When I run my application, do the login etc... my console says: 2010-05-04 23:49:57.297 Framebook Test Application[8069:a0f] /connect/login_success.html But it should also print IT WORKZ to the console, which it does not. Can anyone help me? Thanks.

    Read the article

  • NSString simple pattern matching

    - by SirRatty
    Hi all, Mac OS 10.6, Cocoa project, 10.4 compatibility required. (Please note: my knowledge of regex is quite slight) I need to parse NSStrings, for matching cases where the string contains an embedded tag, where the tag format is: [xxxx] Where xxxx are random characters. e.g. "The quick brown [foxy] fox likes sox". In the above case, I need to grab the string "foxy". (Or nil if no tag is found.) Each string will only have one tag, and the tag can appear anywhere within the string, or may not appear at all. Could someone please help with a way to do that, preferably without having to include another library such as RegexKit. Thank you for any help.

    Read the article

  • Need help with UISearchBar and NSString

    - by guydor
    Hi, I would like to make an if command that checks the value of my UISearchBar in that way if the value of the UISearchBar is equals to " " or multiple spaces without words and chars, an alert will popup. Well, I don't need help with the creation of the alert but I do need help with the if command and the spaces. I know how to do it with multiple "if" command but I want with only 1. Thanks!

    Read the article

  • Check if NSString "000001XX"is a number with intValue

    - by Kenny
    Now I am trying to add a front end check on my app to detect if user input only number in the textfield. I use: - (IBAction)checkID:(UITextField *)sender { if ([sender.text isEqualToString:@""]) { sender.text = @"This information is required"; sender.backgroundColor =[UIColor redColor]; }else if (![sender.text intValue]) { sender.text = [sender.text stringByAppendingString:@" is not valid number"]; sender.backgroundColor =[UIColor redColor]; } NSLog(@"send.text is %@, intValue is %d",sender.text,[sender.text intValue]); } But I found it text begins with number and ends with string, its intValue is still the number. In my text, text is "00001aa", but the intValue is 1. Is there any other way to filter out this "00001aa" text? Thanks in advance.

    Read the article

  • Remove Substring from NSstring

    - by user3037815
    I see so many solution , but none of them was matching my problem . As i am new to iOS development . I have a String abc/_api/web/GetFolderByServerRelativeUrl('Documents/Root Folder/Level 1/Level 2/Level 1-1/Level 1/')/folders. I want to remove Remove Substring after last "/" for example my new string should look like this. abc/_api/web/GetFolderByServerRelativeUrl('Documents/Root Folder/Level 1/Level 2/Level 1-1/Level 1/) Can someone suggest me the best way to achieve this , thanks ,

    Read the article

  • NSData to NSString by changing the value null is returned. I need you help

    - by kevin
    *cipher.h, cipher.m all code : http://watchitlater.com/blog/2010/02/java-and-iphone-aes-interoperability Cipher.m -(NSData *)encrypt:(NSData *)plainText{ return [self transform:KCCEncrypt data:plainText; } step1. Cipher *cipher = [[Cipher alloc]initWithKey:@"1234567890"]; NSData *input = [@"kevin" dataUsingEncoding:NSUTF8StringEncoding]; NSData *data = [cipher encrypt:input]; data variables NSLog print : <4d1c4d7f 1592718c fd588cec 84053e35 step2. NSString *changeVal = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; data variables NSLog print : null NSData to NSString by changing the value null is returned. By converting NSString NSURLConnection want to transfer. I need you help

    Read the article

  • How to take a NSString such as, "0+1+2", get the sum of those and create new string. Obj-C

    - by Ace Legend
    Alright. My app has a text field and next to it are two buttons (Plus button and Equals button). When you press the "Plus" button, it takes the text inside of the textField and adds a "+" to it. Code below: - (IBAction)plusButtonPressed:(id)sender { NSString *plusString = @"+"; NSString *inputString = carbsField.text; NSString *outputString = [NSString stringWithFormat:@"%@%@",inputString,plusString]; NSLog(@"%@",outputString); [carbsField setText:outputString]; } I will eventually make that more intelligent so that I can't put two pluses or whatever. Anyway, then I want the equal button to take whatever is in the textField, which should look something like: "23+54+2.2" and get the sum of those values. I believe I know how to take an Integer and make it a String, but I want to verify it: int *value = 56; NSString *string = @"%d",value; Well, if anyone can show me how to do this, I would be very appreciative. Thanks. EDIT At the moment, I have not tried anything. This is because I do not know where to start. I have an idea of what to do, but I do not know how to execute it. I believe I need to get all characters before a "+" convert them into int and then get the sum of some array of those values.

    Read the article

  • How to convert an NSString to an unsigned int in Cocoa?

    - by Dave Gallagher
    My application gets handed an NSString containing an unsigned int. NSString doesn't have an [myString unsignedIntegerValue]; method. I'd like to be able to take the value out of the string without mangling it, and then place it inside an NSNumber. I'm trying to do it like so: NSString *myUnsignedIntString = [self someMethodReturningAString]; NSInteger myInteger = [myUnsignedIntString integerValue]; NSNumber *myNSNumber = [NSNumber numberWithInteger:myInteger]; // ...put |myNumber| in an NSDictionary, time passes, pull it out later on... unsigned int myUnsignedInt = [myNSNumber unsignedIntValue]; Will the above potentially "cut off" the end of a large unsigned int since I had to convert it to NSInteger first? Or does it look OK to use? If it'll cut off the end of it, how about the following (a bit of a kludge I think)? NSString *myUnsignedIntString = [self someMethodReturningAString]; long long myLongLong = [myUnsignedIntString longLongValue]; NSNumber *myNSNumber = [NSNumber numberWithLongLong:myLongLong]; // ...put |myNumber| in an NSDictionary, time passes, pull it out later on... unsigned int myUnsignedInt = [myNSNumber unsignedIntValue]; Thanks for any help you can offer! :)

    Read the article

  • iPhone SDK. How to assign NSString to UILabel text ?

    - by Del
    If I have a class/object like this #import <Foundation/Foundation.h> @interface anObject : NSObject { NSString *aProp; } @property NSString aProp; @end and in the cellForRowAtIndexPath method i want to assign one of the string values from its properties to a uilabel of a tableviewcell, how do i do it? I've tried this but it doesn't work [[cell topLabel] setText:(NSString *)anObject.aProp]; Putting a breakpoint on the above line and inspecting it, the debugger says "variable is not a CFString Casting the property to a CFString doesnt work Modifying the class and declaring the property as a CFStringRef doesnt work either

    Read the article

  • What is the difference among NSString alloc:initWithCString versus stringWithUTF8String?

    - by mobibob
    I thought these two methods were (memory allocation-wise) equivalent, however, I was seeing "out of scope" and "NSCFString" in the debugger if I used what I thought was the convenient method (commented out below) and when I switched to the more explicit method my code stopped crashing! Notice that I am getting the string that is being stored in my container from sqlite3 query. p = (char*) sqlite3_column_text (queryStmt, 1); // GUID = (NSString*) [NSString stringWithUTF8String: (p!=NULL) ? p : ""]; GUID = [[NSString alloc] initWithCString:(p!=NULL) ? p : "" encoding:NSUTF8StringEncoding]; Also note, that if I looked at the values in the debugger and printed them with NSLog they looked correct, however, I don't think new memory was allocated and the value copied. Instead the memory pointer was stored - went out of scope - referenced later - crash!

    Read the article

  • regular expression to read the string between <title> and </title>

    - by user262325
    Hello every one I hope to read the contents between and in a html string. I think it should be in objective-c @"<title([\\s\\S]*)</title>" below are the codes that rewrited for regular expression //source of NSStringCategory.h #import <Foundation/Foundation.h> #import <regex.h> @interface NSStringCategory:NSObject { regex_t preg; } -(id)initWithPattern:(NSString *)pattern options:(int)options; -(void)dealloc; -(BOOL)matchesString:(NSString *)string; -(NSString *)matchedSubstringOfString:(NSString *)string; -(NSArray *)capturedSubstringsOfString:(NSString *)string; +(NSStringCategory *)regexWithPattern:(NSString *)pattern options:(int)options; +(NSStringCategory *)regexWithPattern:(NSString *)pattern; +(NSString *)null; +(void)initialize; @end @interface NSString (NSStringCategory) -(BOOL)matchedByPattern:(NSString *)pattern options:(int)options; -(BOOL)matchedByPattern:(NSString *)pattern; -(NSString *)substringMatchedByPattern:(NSString *)pattern options:(int)options; -(NSString *)substringMatchedByPattern:(NSString *)pattern; -(NSArray *)substringsCapturedByPattern:(NSString *)pattern options:(int)options; -(NSArray *)substringsCapturedByPattern:(NSString *)pattern; -(NSString *)escapedPattern; @end and .m file #import "NSStringCategory.h" static NSString *nullstring=nil; @implementation NSStringCategory -(id)initWithPattern:(NSString *)pattern options:(int)options { if(self=[super init]) { int err=regcomp(&preg,[pattern UTF8String],options|REG_EXTENDED); if(err) { char errbuf[256]; regerror(err,&preg,errbuf,sizeof(errbuf)); [NSException raise:@"CSRegexException" format:@"Could not compile regex \"%@\": %s",pattern,errbuf]; } } return self; } -(void)dealloc { regfree(&preg); [super dealloc]; } -(BOOL)matchesString:(NSString *)string { if(regexec(&preg,[string UTF8String],0,NULL,0)==0) return YES; return NO; } -(NSString *)matchedSubstringOfString:(NSString *)string { const char *cstr=[string UTF8String]; regmatch_t match; if(regexec(&preg,cstr,1,&match,0)==0) { return [[[NSString alloc] initWithBytes:cstr+match.rm_so length:match.rm_eo-match.rm_so encoding:NSUTF8StringEncoding] autorelease]; } return nil; } -(NSArray *)capturedSubstringsOfString:(NSString *)string { const char *cstr=[string UTF8String]; int num=preg.re_nsub+1; regmatch_t *matches=calloc(sizeof(regmatch_t),num); if(regexec(&preg,cstr,num,matches,0)==0) { NSMutableArray *array=[NSMutableArray arrayWithCapacity:num]; int i; for(i=0;i<num;i++) { NSString *str; if(matches[i].rm_so==-1&&matches[i].rm_eo==-1) str=nullstring; else str=[[[NSString alloc] initWithBytes:cstr+matches[i].rm_so length:matches[i].rm_eo-matches[i].rm_so encoding:NSUTF8StringEncoding] autorelease]; [array addObject:str]; } free(matches); return [NSArray arrayWithArray:array]; } free(matches); return nil; } +(NSStringCategory *)regexWithPattern:(NSString *)pattern options:(int)options { return [[[NSStringCategory alloc] initWithPattern:pattern options:options] autorelease]; } +(NSStringCategory *)regexWithPattern:(NSString *)pattern { return [[[NSStringCategory alloc] initWithPattern:pattern options:0] autorelease]; } +(NSString *)null { return nullstring; } +(void)initialize { if(!nullstring) nullstring=[[NSString alloc] initWithString:@""]; } @end @implementation NSString (NSStringCategory) -(BOOL)matchedByPattern:(NSString *)pattern options:(int)options { NSStringCategory *re=[NSStringCategory regexWithPattern:pattern options:options|REG_NOSUB]; return [re matchesString:self]; } -(BOOL)matchedByPattern:(NSString *)pattern { return [self matchedByPattern:pattern options:0]; } -(NSString *)substringMatchedByPattern:(NSString *)pattern options:(int)options { NSStringCategory *re=[NSStringCategory regexWithPattern:pattern options:options]; return [re matchedSubstringOfString:self]; } -(NSString *)substringMatchedByPattern:(NSString *)pattern { return [self substringMatchedByPattern:pattern options:0]; } -(NSArray *)substringsCapturedByPattern:(NSString *)pattern options:(int)options { NSStringCategory *re=[NSStringCategory regexWithPattern:pattern options:options]; return [re capturedSubstringsOfString:self]; } -(NSArray *)substringsCapturedByPattern:(NSString *)pattern { return [self substringsCapturedByPattern:pattern options:0]; } -(NSString *)escapedPattern { int len=[self length]; NSMutableString *escaped=[NSMutableString stringWithCapacity:len]; for(int i=0;i<len;i++) { unichar c=[self characterAtIndex:i]; if(c=='^'||c=='.'||c=='['||c=='$'||c=='('||c==')' ||c=='|'||c=='*'||c=='+'||c=='?'||c=='{'||c=='\\') [escaped appendFormat:@"\\%C",c]; else [escaped appendFormat:@"%C",c]; } return [NSString stringWithString:escaped]; } @end I use the codes below to get the string between "" and "" NSStringCategory *a=[[NSStringCategory alloc] initWithPattern:@"<title([\s\S]*)</title>" options:0];// Unfortunately [a matchedSubstringOfString:response]] always returns nil I do not if the regular expression is wrong or any other reason. Welcome any comment Thanks interdev

    Read the article

  • Detect if NSString contains a URL and generate a "link" to open inside the app a Safari View

    - by Cy
    I have am reading a twitter feed in my iPhone application and can do it correctly, but I'd like to evolve it in a way to detect if the whole NSString contains any URL or URLs and create a "link" that will open a UIWebView within the same application. Can you guide me on how to perform this task? -(void) setTextTwitter:(NSString *)text WithDate:(NSString*)date { [text retain]; [textTwitter release], textTwitter = nil; textTwitter = text; [date retain]; [dateTwitter release], dateTwitter = nil; dateTwitter = date; [self setNeedsDisplay]; }

    Read the article

  • I get an "EXC_BAD_ACCESS" when I try to read a NSString...

    - by micropsari
    Hello ! This is a (very) simplified version of my iPhone code : @interface x { NSString * name1; NSString * name2; } -init { name1 = @""; name2 = @""; } -(void) a { name1 = @"uhuh"; name2 = [foo bar]; // return a (NSString *) } -(void) b { NSLog(@"%@", name1); // it works NSLog(@"%@", name2); // there I get an EXC_BAD_ACCESS... } Why I have this problem ? And how can I solve it ? Thanks !

    Read the article

  • Crashing Strings.... :( objective-c

    - by Ruiter
    I have in the .h file : NSString *dataHML; NSString *dataHML2; NSString *dataHML3; NSString *dataHML4; NSString *dataHML5; NSString *dataHML6; NSString *dataHMLtotal; in the .m file i merge them with : NSString *dataHtmlTotal = [NSString stringWithFormat:@"%@%@%@%@%@%@", dataHtml, dataHtml2, dataHtml3, dataHtml4,dataHtml5,dataHtml6]; But unfortunately it crashes at some point because of this. Could anyone give me a other solution and post it please, because i already tried nsuserdefault or a nsarray, but without i coudn't get it working :(

    Read the article

  • Reusing a NSString variable - does it cause a memory leak?

    - by Chris S
    Coming from a .NET background I'm use to reusing string variables for storage, so is the code below likely to cause a memory leak? The code is targeting OS X on the iphone/itouch so no automatic GC. -(NSString*) stringExample { NSString *result = @"example"; result = [result stringByAppendingString:@" test"]; // where does "example" go? return result; } What confuses me is an NSStrings are immutable, but you can reuse an 'immutable' variable with no problem.

    Read the article

  • NSString sizeWithFont: returning inconsistent results? known bug?

    - by Olof Hedman
    I'm trying to create a simple custom UIView wich contain a string drawn with a single font, but where the first character is slightly larger. I thought this would be easily implemented with two UILabel:s placed next to eachother. I use NSString sizeWithFont to measure my string to be able to lay it out correctly. But I noticed that the font baseline in the returned rectangle varies with +/- 1 pixel depending on the font size I set. Here is my code: NSString* ctxt = [text substringToIndex:1]; NSString* ttxt = [text substringFromIndex:1]; CGSize sz = [ctxt sizeWithFont: cfont ]; clbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, sz.width, sz.height)]; clbl.text = ctxt; clbl.font = cfont; clbl.backgroundColor = [UIColor clearColor]; [contentView addSubview:clbl]; CGSize sz2 = [ttxt sizeWithFont: tfont]; tlbl = [[UILabel alloc] initWithFrame:CGRectMake(sz.width, (sz.height - sz2.height), sz2.width, sz2.height)]; tlbl.text = ttxt; tlbl.font = tfont; tlbl.backgroundColor = [UIColor clearColor]; [contentView addSubview:tlbl]; If I use 12.0 and 14.0 as sizes, it works fine. But if I instead use 13.0 and 15.0, then the first character is 1 pixel too high. Is this a known problem? Any suggestions how to work around it? Creating a UIWebView with a CSS and HTML page seems way overkill for this. and more work to handle dynamic strings. Is that what I'm expected to do?

    Read the article

  • How do I pass an NSString through 3 ViewControllers?

    - by dBloc
    hey, I'm currently using the iPhone SDK and I'm having trouble passing an NSString through 3 views I am able to pass an NSString between 2 view controllers but I am unable to pass it through another one. My code is as follows... `- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)index`Path { NSString *string1 = nil; NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section]; NSArray *array = [dictionary objectForKey:@"items"]; string1 = [array objectAtIndex:indexPath.row]; //Initialize the detail view controller and display it. ViewController2 *vc2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:[NSBundle mainBundle]]; vc2.string1 = string1; [self.navigationController pushViewController:vc2 animated:YES]; [vc2 release]; vc2 = nil; } in the "ViewController 2" implementations I am able use "string1" in the title bar by doing the following.... - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = string1; UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_time.png"] style:UIBarButtonItemStylePlain //style:UIBarButtonItemStyleBordered target:self action:@selector(goToThirdView)] autorelease]; self.navigationItem.rightBarButtonItem = addButton; } but I also have a NavBar Button on the right side that I would like to push a new view - (void)goToThirdView { ViewController3 *vc3 = [[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:[NSBundle mainBundle]]; [self.navigationController pushViewController:NESW animated:YES]; vc3.string1 = string1 ; [vc3 release]; vc3 = nil; } How do I pass on that same string to the third view? (or fourth)

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >