惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
Project Zero
Project Zero
D
DataBreaches.Net
I
InfoQ
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Vercel News
Vercel News
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
The Hacker News
The Hacker News
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Scott Helme
Scott Helme
T
Threatpost
爱范儿
爱范儿
N
Netflix TechBlog - Medium
D
Docker
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
K
Kaspersky official blog
H
Help Net Security
S
Secure Thoughts
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
G
Google Developers Blog
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
B
Blog
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog

博客园 - pensir

ef报错:实体类型XXX不是当前上下文的模型的一部分。 让AutoCAD.NET支持后台线程 将cad嵌入到vb中 sql server 2005 msxml安装失败解决及msxml 6.0 卸载 智能替换DataTable.Select中会导致错误的单引号 - pensir - 博客园 CADVBA代码移植到.NET 最全ASCII码对照表(备用) 在VB.NET中使用MS Access存储过程(转载) Access存储过程,环境:VB 2005+.NET2.0+ACCESS2003(转载) 关键性代码整理 WinForm窗体间传值 WinForm主要控件分类一览 MaskedTextBox掩码元素一览 ArcGIS中的坐标系统 Geodatabase组织结构 GIS关键词 栅格数据与矢量数据 ArcGIS的文件结构 winform+c#之窗体之间的传值 - pensir - 博客园
C# 删除字符串中任何位置的空格 - pensir - 博客园
pensir · 2010-04-21 · via 博客园 - pensir

你或许知道你能使用String.Trim方法去除字符串的头和尾的空格,不幸运的是. 这个Trim方法不能去除字符串中间的C#空格。  

  static void Main()
        {
            //demo1     除去空格,提取出各个单词
            string s = "a b c";
            string[] word = s.Split(new char[] { ' ' });
            foreach (string temp in word)
                Console.WriteLine(temp);

            //demo2     直接去除所有空格
            s=s.Replace(" ","");
            Console.WriteLine(s);

            //demo3     去掉首尾空格
            s = " aaa ";
            s = s.Trim();
            Console.WriteLine(s);
        }       

另一版本如下:    

    1. string text = "  My test\nstring\r\n is\t quite long  ";  
    2. string trim = text.Trim(); 

        这个'trim' 字符串将会是:

        "My test\nstring\r\n is\t quite long"  (31 characters)

        另一个清除C#空格方法是使用 String.Replace 方法, 但是这需要你通过调用多个方法来去除个别C#空格:

    1. string trim = text.Replace( " """ );  
    2. trim = trim.Replace( "\r""" );  
    3. trim = trim.Replace( "\n""" );  
    4. trim = trim.Replace( "\t""" ); 

        这里最好的方法就是使用正则表达式.你能使用Regex.Replace方法, 它将所有匹配的替换为指定的字符.在这个例子中,使用正则表达式匹配符"\s",它将匹配任何空格包含在这个字符串里C#空格, tab字符, 换行符和新行(newline).

    1. string trim = Regex.Replace( text, @"\s""" ); 

        这个'trim' 字符串将会是:

    1. "Myteststringisquitelong"  (23 characters)