nsstring字符串重组
//
// main.m
// 05-字符串重组
//
// Created by apple on 14-3-20.
// Copyright (c) 2014年 apple. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
//1.多个数据拼接成一个字符串
int year = 1988;
int month = 4;
int day = 15;
NSString * date = [NSString stringWithFormat:@"%d年%d月%d日",year,month,day];
NSLog(@"date %@",date);
NSString * address = @"昌平区,金燕龙";
NSString * dateAndAddrss = [NSString stringWithFormat:@"%@地址:%@",date,address];
NSLog(@"dateAndAddress %@",dateAndAddrss);
//2.字符串的末尾追加新的字符
NSString * str1 = @"www.";
NSString * str2 = [str1 stringByAppendingString:@"itcast.cn"];
NSLog(@"str2 %@ str1 %@",str2,str1);
//3.在制定的范围追加字符串
NSString * str3 = @"www.cn";
NSRange range = {4,0};
// 4 location代表的时从哪个索引开始插入,length 代表的意思可以覆盖几个字符
NSString * str4 = [str3 stringByReplacingCharactersInRange:range withString:@"itcast."];
NSLog(@"str4 %@",str4);
//4.使用新的字符,替换原有的字符
NSString * str5 = @"www.itcast.cn";
NSString * str6 = [str5 stringByReplacingOccurrencesOfString:@"w" withString:@"a"];
NSLog(@"str6 %@",str6);
//5.在字符串中删除特定的某些字符 胡汉三 hhs
NSString * str7 = @"www---.itcatst.--cn";
NSString * str8 = [str7 stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSLog(@"str8 %@",str8);
//6.去掉字符串中的空格
NSString * str9 = @"www .itcat .cn";
NSString * str10 = [str9 stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"str10 %@",str10);
}
return 0;
}
nsstring字符串重组的更多相关文章
- 小白学开发(iOS)OC_ 字符串重组(2015-08-13)
// // main.m // 字符串重组 // // Created by admin on 15/8/13. // Copyright (c) 2015年 admin. All right ...
- OC NSString(字符串)
OC NSString(字符串) 多行文字字面量 NSString * string = @"abC" @"DEF" @"hjk" @&qu ...
- NSString字符串
要把 “2011-11-29” 改写成 “2011/11/29”一开始想用ios的时间格式,后来用NSString的方法搞定. [string stringByReplacingOccurrences ...
- 【去除NSString 字符串中的空格换行符】
@interface NSString (DeletWhiteSpace) // 返回一个去掉前后空格的字符串或者下划线,如果自己是一个nil 返回@“” - (NSString *)trimming ...
- iOS - OC NSString 字符串
前言 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSSecureCoding> @interface NSM ...
- Objective - C 中NSString (字符串)与C中的字符串转换问题
NSString是一个常用的类,NSString是原生支持unicode C中的字符串 比如char * a = "hello world"; 是utf8类型的, char* d ...
- NSString字符串类型-学习总结
1.字符串的创建 (1)创建常量字符串 NSString *str = @"This is a String"; //str是变量名 (2)创建空的字符串,给字符串赋值 NSStr ...
- 截取NSString字符串
NSString类中提供了这样三个方法用于获取子字符串: – substringFromIndex: – substringWithRange: – substringToIndex: 具体的使用见下 ...
- NSString 字符串操作
//一.NSString /*----------------创建字符串的方法----------------*/ //1.创建常量字符串. NSString *astring = @"Th ...
随机推荐
- python 安装pip的时候出现UnicodeEncodeError错误
另外 Python 中一个比较常见的问题是编码问题,若遇到类似"UnicodeEncodeError: 'ascii' codec can't encode character u'\u62 ...
- POJ 1185 经典状压dp
做了很久的题 有注释 #include<stdio.h> #include<string.h> #include<algorithm> #include<ma ...
- Mininet实验 基于Mininet实现BGP路径挟持攻击实验
参考:基于Mininet实现BGP路径挟持攻击实验 实验目的: 掌握如何mininet内模拟AS. 掌握BGP路径挟持的原理和分析过程. 实验原理: 互联网是由相互连接的自治系统AS组成的,通过一个通 ...
- 【转载】wireshark:no interface can be used for capturing in this system with the current configuration
转自:wireshark:no interface can be used for capturing in this system with the current configuration 通过 ...
- WCF Basic Concept
http://msdn.microsoft.com/library/ee354180.aspx Steps: Designing a Service Contract Implementing a W ...
- java,for循环中的穷举、迭代、冒泡例题
1.100以内与7相关的数 //100以内与7相关的数: public static void main1(String[] args) { for(int i=1;i<=100;i++){ i ...
- Delphi深度探索-CodeSite应用指南
Delphi深度探索-CodeSite应用指南 Delphi虽然为我们提供极其强大的调试功能,查找Bug仍然是一项艰巨的工作,通常我们写代码和调试代码的所消耗的时间是大致相同的,甚至有可能更多.为了减 ...
- NRF51822之app_button使用
我们现在开始使用app_button,为什么要使用这个来替代直接使用GPIOTE呢? 因为我们在手册中可以看到如果一直开启GPIOTE in模式的需要需要很大电流.所以我们需要使用RTC来“周期”的查 ...
- jQuery.mobile.activePage获取当点活动的page
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- ssh2 php扩展
如何通过PHP启动和关闭远程服务器上的某个软件,譬如Memcached.对于俺这个刚刚掌握PHP编程皮毛的菜鸟来说,最直接不过的想法就是用exec函数执行SSH命令呗,先把运行Apache+PHP的服 ...