VB.Net Split的4种使用方法

来源:百度文库 编辑:神马文学网 时间:2024/06/13 01:30:19
4个关于split的实例

1. 简单的split分割字符串

首先我们拿了一个带多个空格的字符串来做分割. 我们分配一个New Char() array 保存为String() array 来储存我们例子中的那些分割后的单词.最后,我们用loop循环来遍历和显示这些分割后的字母集合.

=== Program that uses Split on String (VB.NET) ===Module Module1Sub 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 StringFor Each word In wordsConsole.WriteLine(word)NextEnd SubEnd Module=== Output of the program ===Our 
website 
address 
is 
www.lob.cn

2. 分割一个完整文件路径

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 Module1Sub 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 StringFor Each part In partsConsole.WriteLine(part)NextEnd SubEnd Module=== Output of the program ===C:UsersSamDocumentsPerls乐博网