首先我们拿了一个带多个空格的字符串来做分割. 我们分配一个New Char() array 保存为String() array 来储存我们例子中的那些分割后的单词.最后,我们用loop循环来遍历和显示这些分割后的字母集合.
=== Program that uses Split on String (VB.NET) ===Module Module1 Sub Main()' We want to split this input stringDim s As String = "Our website address is www.lob.cn"' Split string based on spacesDim words As String() = s.Split(New Char() {" "c})' Use For Each loop over words and display themDim word As String For Each word In words Console.WriteLine(word) Next End Sub End Module=== Output of the program ===Our
website
address
is
www.lob.cn
Here we see how you can Split a file system path into separate parts using Visual Basic .NET. We use a New Char() array with one string, "\""c, and then loop through and display the results.
=== Program that splits file path (VB.NET) ===Module Module1 Sub Main()' The file system path we need to splitDim s As String = "C:\Users\Sam\Documents\Perls\乐博网"' Split the string on the backslash characterDim parts As String() = s.Split(New Char() {"\"c})' Loop through result strings with For EachDim part As String For Each part In parts Console.WriteLine(part) Next End Sub End Module=== Output of the program ===C: Users Sam Documents Perls 乐博网
联系客服