久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

vb.net split字符串分割函數(shù)的用法

 hqpek 2019-11-18

VB.NET Split函數(shù)使你能夠?qū)㈤L(zhǎng)字符串分離為單獨(dú)的字;但是如果在字與字之間不止一個(gè)空格,,Split就會(huì)返回一個(gè)錯(cuò)誤的結(jié)果,。為了防止這種情況發(fā)生,你可以在使用Split之前用Replace函數(shù)來替換多個(gè)空格的出現(xiàn),。列表A給出了一個(gè)例子。

名稱說明
Split(Char[])

基于數(shù)組中的字符將字符串拆分為多個(gè)子字符串,。


Split(Char[],?Int32)

基于數(shù)組中的字符將一個(gè)字符串拆分成最大數(shù)量的子字符串,。 也可指定要返回的子字符串的最大數(shù)量。


Split(Char[],?Int32,?StringSplitOptions)

基于數(shù)組中的字符將一個(gè)字符串拆分成最大數(shù)量的子字符串,。


Split(Char[],?StringSplitOptions)

基于數(shù)組中的字符將字符串拆分為多個(gè)子字符串,。 可以指定子字符串是否包含空數(shù)組元素。


Split(String[],?Int32,?StringSplitOptions)

基于數(shù)組中的字符串將一個(gè)字符串拆分成最大數(shù)量的子字符串,。 可以指定子字符串是否包含空數(shù)組元素,。


Split(String[],?StringSplitOptions)

基于數(shù)組中的字符串將字符串拆分為多個(gè)子字符串。 可以指定子字符串是否包含空數(shù)組元素,。


Private Sub CountWords()  
Dim strText As String = "It's a wonderfulworld" 
Dim iCount As Integer  
 
Do While (strText.IndexOf(Space(2)) >= 0)  
strTextstrText = strText.Replace(Space(2), Space(1))  
Loop  
iCount = Split(strText, Space(1)).Length  
MsgBox(iCount.ToString())  
End Sub

在這個(gè)例子中,,我創(chuàng)建了字符串strText,再將它設(shè)置成有多個(gè)字符的長(zhǎng)字符串,。然后,,我利用Replace函數(shù)來把出現(xiàn)的多個(gè)空格替換成一個(gè)空格。這樣做是為了把字符串strText準(zhǔn)備就緒,,讓你能夠使用VB.NET Split函數(shù)并提供正確的結(jié)果,。接著,我將strText輸入Split函數(shù),,并且得到了包括在字符串strText中的字?jǐn)?shù),。

注意:如果你跳過或注釋用來移除多余空格的循環(huán),結(jié)果是7個(gè)字,。使用移除所有多余空格的循環(huán)后,,結(jié)果才是正確的,4個(gè)字,。


VB.NET Split使用方法一. 簡(jiǎn)單的split分割字符串

首先我們拿了一個(gè)帶多個(gè)空格的字符串來做分割. 我們分配一個(gè)New Char() array 保存為String() array 來儲(chǔ)存我們例子中的那些分割后的單詞.最后,,我們用loop循環(huán)來遍歷和顯示這些分割后的字母集合.

=== Program that uses Split on String (VB.NET) ===  
Module Module1  
Sub Main()  
' We want to split this input string  
Dim s As String = "Our website address is www.51cto.cn" 
' Split string based on spaces  
Dim words As String() = s.Split(New Char() {" "c})  
' Use For Each loop over words and display them  
Dim word As String  
For Each word In words  
Console.WriteLine(word)  
Next  
End Sub  
End Module 
=== Output of the program ===  
Our   
website   
address   
is

  

VB.NET Split使用方法二. 分割一個(gè)完整文件路徑

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 split  
Dim s As String = "C:\Users\Sam\Documents\Perls\51cto" 
' Split the string on the backslash character  
Dim parts As String() = s.Split(New Char() {"\"c})  
' Loop through result strings with For Each  
Dim 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

 

 

VB.NET Split使用方法三. 根據(jù)單詞分割語(yǔ)句 這里用了正則表達(dá)式

Imports System.Text.RegularExpressions  
Module Module1  
Sub Main()  
' Declare iteration variable  
Dim s As String  
' Loop through words in string  
Dim arr As String() = SplitWords(".Net Fans's QQ group No is 40797788, man!")  
' Display each word. Note that punctuation is handled correctly.  
For Each s In arr  
Console.WriteLine(s)  
Next  
Console.ReadLine()  
End Sub  
''' <summary> 
''' Split the words in string on non-word characters.  
''' This means commas and periods are handled correctly.  
''' summary> 
Private Function SplitWords(ByVal s As String) As String()  
'  
' Call Regex.Split function from the imported namespace.  
' Return the result array.  
'Return Regex.Split(s, "\W+")  
End Function  
End Module 
=== Output of the program ===  
第一行是空白  
Net ---- 這個(gè)是第2行了  
Fans  
s   
QQ   
group   
No   
is   
40797788  
man

 

VB.NET Split使用方法四. 分割一個(gè)文本文件中的每行

Imports System.IO  
Module Module1  
Sub Main()  
Dim i As Integer = 0 
'vb.net  
' Loop through each line in array returned by ReadAllLines  
Dim line As String  
For Each line In File.ReadAllLines("example.txt")  
' Split line on comma  
Dim parts As String() = line.Split(New Char() {","c})  
' Loop over each string received  
Dim part As String  
For Each part In parts  
' Display to Console  
Console.WriteLine("{0}:{1}", i, part)  
Next  
i += 1  
Next  
End Sub  
End Module 
=== Output of the program ===  
0:frontal  
0:parietal  
0:occipital  
0:temporal  
1:pulmonary artery  
1:aorta  
1:left ventricle

 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多