IOS简单的字串替换方法stringByTrimmingCharactersInSet 和空格的替换 ()

 1 NSString *str = @"一个 (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn 汉0932字#@!中..文//>?输[email protected]#$#@%#^#^%&^*&(*)入";
 2     NSMutableCharacterSet *set = [[NSMutableCharacterSet alloc] init];
 3     [set formUnionWithCharacterSet:[NSCharacterSet lowercaseLetterCharacterSet]];//小写字母
 4     NSLog(@"1 %@",[str stringByTrimmingCharactersInSet:set]);
 5     [set formUnionWithCharacterSet:[NSCharacterSet uppercaseLetterCharacterSet]];//大写字母
 6     NSLog(@"2 %@",[str stringByTrimmingCharactersInSet:set]);
 7     [set formUnionWithCharacterSet:[NSCharacterSet symbolCharacterSet]];//符号
 8     NSLog(@"3 %@",[str stringByTrimmingCharactersInSet:set]);
 9     [set formUnionWithCharacterSet:[NSCharacterSet punctuationCharacterSet]];//标点
10     NSLog(@"4 %@",[str stringByTrimmingCharactersInSet:set]);
11     [set formUnionWithCharacterSet:[NSCharacterSet controlCharacterSet]];//控制符
12     NSLog(@"5 %@",[str stringByTrimmingCharactersInSet:set]);
13     [set formUnionWithCharacterSet:[NSCharacterSet decimalDigitCharacterSet]];//小数
14     NSLog(@"6 %@",[str stringByTrimmingCharactersInSet:set]);
15     [set formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];//文字
16     NSLog(@"7 %@",[str stringByTrimmingCharactersInSet:set]);
17     [set formUnionWithCharacterSet:[NSCharacterSet nonBaseCharacterSet]];//非基础
18     NSLog(@"8 %@",[str stringByTrimmingCharactersInSet:set]);
19     [set formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];//字母数字
20     NSLog(@"9 %@",[str stringByTrimmingCharactersInSet:set]);
21     [set formUnionWithCharacterSet:[NSCharacterSet decomposableCharacterSet]];//可分解
22     NSLog(@"10 %@",[str stringByTrimmingCharactersInSet:set]);
23     [set formUnionWithCharacterSet:[NSCharacterSet illegalCharacterSet]];//非法
24     NSLog(@"11 %@",[str stringByTrimmingCharactersInSet:set]);
25     [set formUnionWithCharacterSet:[NSCharacterSet capitalizedLetterCharacterSet]];//大写
26     NSLog(@"12 %@",[str stringByTrimmingCharactersInSet:set]);
27     [set formUnionWithCharacterSet:[NSCharacterSet newlineCharacterSet]];//换行符
28     NSLog(@"13 %@",[str stringByTrimmingCharactersInSet:set]);
29     [set formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];//空格换行
30     NSLog(@"14 %@",[str stringByTrimmingCharactersInSet:set]);

1 2012-07-26 19:11:01.863 yingkong1987[12876:fb03] 1 一个 (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn 汉0932字#@!中..文//>?输[email protected]#$#@%#^#^%&^*&(*)入
 2 2012-07-26 19:11:01.864 yingkong1987[12876:fb03] 2 一个 (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn 汉0932字#@!中..文//>?输[email protected]#$#@%#^#^%&^*&(*)入
 3 2012-07-26 19:11:01.864 yingkong1987[12876:fb03] 3 一个 (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn 汉0932字#@!中..文//>?输[email protected]#$#@%#^#^%&^*&(*)入
 4 2012-07-26 19:11:01.864 yingkong1987[12876:fb03] 4 一个 (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn 汉0932字#@!中..文//>?输[email protected]#$#@%#^#^%&^*&(*)入
 5 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 5 一个 (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn 汉0932字#@!中..文//>?输[email protected]#$#@%#^#^%&^*&(*)入
 6 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 6 一个 (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn 汉0932字#@!中..文//>?输[email protected]#$#@%#^#^%&^*&(*)入
 7 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 7  (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn
 8 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 8  (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn
 9 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 9  (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn
10 2012-07-26 19:11:01.866 yingkong1987[12876:fb03] 10  (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn
11 2012-07-26 19:11:02.170 yingkong1987[12876:fb03] 11  (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn
12 2012-07-26 19:11:02.170 yingkong1987[12876:fb03] 12  (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn
13 2012-07-26 19:11:02.170 yingkong1987[12876:fb03] 13  (ABC) #@!#^#[email protected]#[email protected]!212s012yhsn
14 2012-07-26 19:11:02.170 yingkong1987[12876:fb03] 14 

原文转自 :http://blog.csdn.net/huifeidexin_1/article/details/7977857

时间: 2024-08-04 18:03:15

IOS简单的字串替换方法stringByTrimmingCharactersInSet 和空格的替换 ()的相关文章

查询某个分组中多行字段值的拼接字串的方法--access

查询某个分组中多行字段值的拼接字串的方法 先收藏,后面再研究 access的SQL语法中没有自定义函数,也不能象SQL Server中一样用变量.游标.子查询等方法来灵活处理查询语句. 但是,在Access环境中,透过模块中的过程,可利用功能强大的VB语言,生成复杂需求的查询语句. 下面是本人今天在Access版块中的一个回复,以此例 access的SQL语法中没有自定义函数,也不能象SQL Server中一样用变量.游标.子查询等方法来灵活处理查询语句. 但是,在Access环境中,透过模块中

SPutils,存取简单的字串,int,boolean及javabean对象

可以结合Gson对javabean转化成字符串实现对象的存取,基本代码如下 package com.example.luozhenlonghp.project_aidl_demo; import android.content.Context; import android.content.SharedPreferences; /** * use for save data of String,int,boolean,list<anybean> * Created by luozhenlong

JS判断字符串变量是否含有某个字串的方法

var aa = "bbmemorycc"; var i = aa.indexOf("memory"); if(i>-1){ 表示存在 }

【通过操作指针,与指针做函数參数&amp;#39;实现字串在主串中出现的次数,然后将出现的部分依照要求进行替换 】

#include<stdio.h> #include<stdlib.h> int strTime(const char *str1, const char *str2, int *time) { int count = 0; char *p1 = str1; char *p2 = str2; //p1是第一次出现的位置 p1 = strstr(p1, p2); //注意这里不要写成*p1!=NULL 由于p1 是null的地址一旦读取*p1 会出错的!!!!不能读取操作系统的数据

c#调用dll接口传递utf-8字串方法

1. 起源: VCU10之视频下载模块,采用纯python实现,c++代码调用pythonrun.h配置python运行环境启动python模块,以使界面UI能够使用其中功能. 棘手问题!用去一天时间反复打印日志,验证所传字串区别,以期望发现问题定位问题,直至下班前始有灵感. 验证发现,非中文字符可以正常下载,中文字符下载解析失败,当时即想到可能是字串不统一所致,就在python代码中做字串转换处理,均不奏效. 原接口封装代码如下: [DllImport("VideoDownloader&quo

公共字串计算——String.regionMatches方法 &amp; Java标签

题目:输入两个字符串,计算两个字符串的最大公共字串的长度,并输出,字符不区分大小写 eg:输入abcde  xxxBcyyy,输出 2. 完整Java代码: import java.util.*; public class Main { public static void main(String arg[]){ Scanner s=new Scanner(System.in); String str1=s.next(); String str2=s.next(); s.close(); Str

QuickText | 热字串自动替换

分类: 办公支持    版本: 0.0.1    发布日期: 2015-07-09 热字串自动替换生成工具,根据指定的条件(选项)快速生成热字串脚本:Hotstring.ahk 功能简介 两栏窗口,左侧为热字串选项设置,右侧为热字串编辑列表 热字串选项支持“全局选项”及“独立选项” “独立选项”覆盖“全局选项”设置 如要设置独立选项,需选中“独立选项”单选按钮 启用“独立选项”时,可实时生成选项代码 未安装 AutoHotkey.exe 时,执行脚本需自带 Hotstring.exe 程序 热字

通过操作指针,与指针做函数参数&#39;实现字串在主串中出现的次数,然后将出现的部分按照要求进行替换

#include<stdio.h> #include<stdlib.h> int strTime(const char *str1, const char *str2, int *time) { int count = 0; char *p1 = str1; char *p2 = str2; //p1是第一次出现的位置 p1 = strstr(p1, p2); //注意这里不要写成*p1!=NULL 因为p1 是null的地址一旦读取*p1 会出错的!!!!不能读取操作系统的数据

java之字符串中查找字串的常见方法

1.int indexOf(String str) :返回第一次出现的指定子字符串在此字符串中的索引.      int indexOf(String str, int startIndex):从指定的索引处开始,返回第一次出现的指定子字符串在此字符串中的索引. 函数数名:indexOf 调用方式:Object(String).indexOf(String str,int startIndex)或String.indexOf(String str) 参数说明:str需要查找的字串. startI