Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » Oracle  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 [求助]如何删除(或者替换)字段中连续的空白?
palatum



CJSDN高级会员


发贴: 451
积分: 80
于 2006-03-28 18:04 user profilesend a private message to usersend email to palatumsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
[Oracle 10g]用户输入的数据中间有大段的空白,基本上是全角空格,半角空格。如何方便地将连续空白换成一个空格?

谢了。


palatum edited on 2006-03-28 18:34

作者 Re:[求助]如何删除(或者替换)字段中连续的空白? [Re:palatum]
zcjl

涅槃



发贴: 537
积分: 65
于 2006-03-28 21:58 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
用正则表达式可以吗?


作者 Re:[求助]如何删除(或者替换)字段中连续的空白? [Re:zcjl]
palatum



CJSDN高级会员


发贴: 451
积分: 80
于 2006-03-29 07:59 user profilesend a private message to usersend email to palatumsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
zcjl wrote:
用正则表达式可以吗?

无所谓用什么,只要能达到目的就行。最好有代码。



作者 Re:[求助]如何删除(或者替换)字段中连续的空白? [Re:palatum]
zcjl

涅槃



发贴: 537
积分: 65
于 2006-03-29 09:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TestBlank {
public static void main(String[] args) {
String str = "1      2    3 4";
String regex = " +| +";
System.out.println(str.replaceAll(regex, " "));
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
System.out.println(m.replaceAll(" "));
}
}

说明:
1.待替换的str中包含了全角和半角空格
2.正则表达式regex第一个空白是全局空格,第二个空白是半角空格
3.可以直接使用String对象的replaceAll方法(第一个参数为正则表达式),也可以使用regex包中的Pattern和Matcher来进行基于正则表达式的查找、替换



作者 Re:[求助]如何删除(或者替换)字段中连续的空白? [Re:palatum]
palatum



CJSDN高级会员


发贴: 451
积分: 80
于 2006-03-29 12:18 user profilesend a private message to usersend email to palatumsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
多谢。



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923