修剪数组中的所有空格

时间:2009-11-27 03:29:17

标签: vb.net

如何修剪数组中的所有空格?

Dim str() As String = {"Tyrannosaurus", _
       "Amarga saurus", _
       " Mamenchisaurus", _
       "Brachios aurus", _
       "Deinonychus", _
       "Tyr annosaurus", _
       " Compsognathus"}

2 个答案:

答案 0 :(得分:3)

str = str.Select(Function(s) s.Replace(" ", "")).ToArray()

答案 1 :(得分:1)

Dim reg As New Regex("\s*")
For i = 0 To temp.Length - 1
    temp(i) = reg.Replace(temp(i), "")
Next i