hjwb.net
当前位置:首页 >> 字符串去掉换行符 >>

字符串去掉换行符

string l_strResult = 你的字符串.Replace("\n", "").Replace(" ","").Replace("\t","").Replace("\r","");

假定要处理的字符串放在变量s中: s = Replace(Replace(s, vbCr, ""), vbLf, "")

C# 函数: Replace 下面是C# replace 使用方法 string str = "aaaa\n bbbb";str.Replace(" ","");str.Replace("\n",""); TextBox1.Text.Trim().Replace("\r\n", ""); //去掉空格和换行。

如果要去掉前后的用trim 如果要去掉任何地方出现的用replace

把回车换行符换成空格 REPLACE(@c,char(13),' ') 把空格换成回车换行符 REPLACE(@c,' ',char(13))

例如有一个字符串char str[] 首先搞清楚字符串的长度,比如说是l,那么最后一个字符是l-1,也就是'\n' str[l-1] = '\0' 直接把换行替换成结束符,之后字符串就会被认为到这里结束了

trim只能去除空字符,replace去除了所有的vbcrlf,要考虑保留字符串中间的vbcrlf,还要考虑字符串最后的换行符可能会有多个...如下是个思路: Function myTrim(ByVal s As String) As String Dim Length As Long Dim Char As String s = Trim(s)...

正则表达式没学过? import java.util.regex.Matcher; import java.util.regex.Pattern; public class StringUtils { /** *正则 */ public static String replaceBlank(String str) { String dest = ""; if (str!=null) { Pattern p = Pattern.c...

String filePath = "D://111//11.txt"; BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath))); while((str=br.readLine())!=null) { String s =str; s.replace("\r",""); s.replace("\t",""); }

windows字符串中的换行符="\r\n" replaceAll(yourString,"\r\n",""); public static String replaceAll(String str, String old, String news) { if(str == null) return str; int begin = 0; int idx = 0; int len = old.length(); StringBuff...

网站首页 | 网站地图
All rights reserved Powered by www.hjwb.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com