分割多个空格字符串 [英] spliting multiple space string

查看:85
本文介绍了分割多个空格字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想拆分我的声明

我的陈述就是这样

Hi all i want to Split my Statement

My statement is like this

"This is       CAR"


通过使用split函数,我只能拆分一个spcae,但是在我的声明中,在issp之后有很多空间,

如何避免出现多个空格?


By using split function i can split only one spcae,but in my statement ther are many space after is,

How I can avoid mulitple spaces?

推荐答案

使用 ^ ]像这样:

Use String.Split(Char[], StringSplitOptions)[^] like this:

String   t = "This is  a  CAR ";
String[] r = String.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);



此示例使用C#,但应易于转换为VB.NET.

干杯!

—MRB



This sample is in C#, but should be easily translatable to VB.NET.

Cheers!

—MRB


类似的方法应该起作用

Something like this should work

Dim t As String = " Some    string with   lots of    spaces  "
Dim r As String() = t.Split(New Char() {" "c}, 
    StringSplitOptions.RemoveEmptyEntries)



我刚刚意识到这个问题已经4天了!我不知道为什么在新问题部分?
无论如何,现在可以在这里使用它了:)



I just realized this question is 4 days old! I have no idea why it was in the new questions section??
Anyway its here now for someone to use :)


当然,您应该只使用类型为System.StringSplitOptionsSystem.String.Split的第二个参数.如果使用System.StringSplitOptions.RemoveEmptyEntries,您将满足您的(正确)要求-易于检查.

就这么简单.

—SA
Sure, you should only use a second parameter of System.String.Split of the type System.StringSplitOptions. You will meet your (correct) requirements if you use System.StringSplitOptions.RemoveEmptyEntries — easy to check up.

Just as simple as this.

—SA


这篇关于分割多个空格字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆