NSString+NSMutableString+NSValue+NSAraay用法汇总3

//扩展路径

    NSString *Path = @"~/NSData.txt";
    NSString *absolutePath = [Path stringByExpandingTildeInPath];
    NSLog(@"absolutePath:%@",absolutePath);
    NSLog(@"Path:%@",[absolutePath stringByAbbreviatingWithTildeInPath]);



    //文件扩展名
    NSString *Path = @"~/NSData.txt";
    NSLog(@"Extension:%@",[Path pathExtension]);




    /*******************************************************************************************
     NSMutableString
     *******************************************************************************************/   

    /*---------------给字符串分配容量----------------*/
    //stringWithCapacity:
    NSMutableString *String;
    String = [NSMutableString stringWithCapacity:40];


    /*---------------在已有字符串后面添加字符----------------*/   

    //appendString: and appendFormat:

    NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
    //[String1 appendString:@", I will be adding some character"];
    [String1 appendFormat:[NSString stringWithFormat:@", I will be adding some character"]];
    NSLog(@"String1:%@",String1);
    */


    /*-------- 在已有字符串中按照所给出范围和长度删除字符------*/   
    /*
     //deleteCharactersInRange:
     NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
     [String1 deleteCharactersInRange:NSMakeRange(0, 5)];
     NSLog(@"String1:%@",String1);



     /*--------在已有字符串后面在所指定的位置中插入给出的字符串------*/

    //-insertString: atIndex:
    NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
    [String1 insertString:@"Hi! " atIndex:0];
    NSLog(@"String1:%@",String1);



    /*--------将已有的空符串换成其它的字符串------*/

    //-setString:
    NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
    [String1 setString:@"Hello Word!"];
    NSLog(@"String1:%@",String1);



    /*--------按照所给出的范围,和字符串替换的原有的字符------*/

    //-setString:
    NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
    [String1 replaceCharactersInRange:NSMakeRange(0, 4) withString:@"That"];
    NSLog(@"String1:%@",String1);



    /*-------------判断字符串内是否还包含别的字符串(前缀,后缀)-------------*/
    //01: 检查字符串是否以另一个字符串开头- (BOOL) hasPrefix: (NSString *) aString;
    NSString *String1 = @"NSStringInformation.txt";
    [String1 hasPrefix:@"NSString"] = = 1 ?  NSLog(@"YES") : NSLog(@"NO");
    [String1 hasSuffix:@".txt"] = = 1 ?  NSLog(@"YES") : NSLog(@"NO");

    //02: 查找字符串某处是否包含其它字符串 - (NSRange) rangeOfString: (NSString *) aString,这一点前面在串中搜索子串用到过;

你可能感兴趣的:(NSString+NSMutableString+NSValue+NSAraay用法汇总3)