成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

VB.NET Split使用方法寶典

開發 后端
VB.NET Split使用方法你都知道嗎?在這里我們為你介紹三種方法:1簡單的split分割字符串,2分割一個完整文件路徑,3根據單詞分割語句 這里用了正則表達式。

在學習中我們要善于總結,總結對我們有很大的幫助,可以加快我們學習的步伐。在這里我給大家總結一下關于VB.NET Split使用方法,希望朋友們在工作學習中總結出更多的方法。

VB.NET Split使用方法一. 簡單的split分割字符串

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

  1. === Program that uses Split on String (VB.NET) ===  
  2. Module Module1  
  3. Sub Main()  
  4. ' We want to split this input string  
  5. Dim s As String = "Our website address is www.51cto.cn" 
  6. ' Split string based on spaces  
  7. Dim words As String() = s.Split(New Char() {" "c})  
  8. ' Use For Each loop over words and display them  
  9. Dim word As String  
  10. For Each word In words  
  11. Console.WriteLine(word)  
  12. Next  
  13. End Sub  
  14. End Module 
  15. === Output of the program ===  
  16. Our   
  17. website   
  18. address   
  19. is  

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

  1. 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. 
  2. === Program that splits file path (VB.NET) ===  
  3. Module Module1  
  4. Sub Main()  
  5. ' The file system path we need to split  
  6. Dim s As String = "C:\Users\Sam\Documents\Perls\51cto" 
  7. ' Split the string on the backslash character  
  8. Dim parts As String() = s.Split(New Char() {"\"c})  
  9. ' Loop through result strings with For Each  
  10. Dim part As String  
  11. For Each part In parts  
  12. Console.WriteLine(part)  
  13. Next  
  14. End Sub  
  15. End Module 
  16. === Output of the program ===  
  17. C:  
  18. Users  
  19. Sam  
  20. Documents  
  21. Perls  

VB.NET Split使用方法三. 根據單詞分割語句 這里用了正則表達式

  1. Often you need to extract the words from a String or sentence in VB.NET. The code here needs to handle punctuation 
    and non-word characters differently than the String Split method. Here we use Regex.Split to parse the 
    words. 
  2. === Program that splits words (VB.NET) ===  
  3. Imports System.Text.RegularExpressions  
  4. Module Module1  
  5. Sub Main()  
  6. ' Declare iteration variable  
  7. Dim s As String  
  8. ' Loop through words in string  
  9. Dim arr As String() = SplitWords(".Net Fans's QQ group No is 40797788, man!")  
  10. ' Display each word. Note that punctuation is handled correctly.  
  11. For Each s In arr  
  12. Console.WriteLine(s)  
  13. Next  
  14. Console.ReadLine()  
  15. End Sub  
  16. ''' <summary> 
  17. ''' Split the words in string on non-word characters.  
  18. ''' This means commas and periods are handled correctly.  
  19. ''' summary> 
  20. Private Function SplitWords(ByVal s As String) As String()  
  21. '  
  22. ' Call Regex.Split function from the imported namespace.  
  23. ' Return the result array.  
  24. 'Return Regex.Split(s, "\W+")  
  25. End Function  
  26. End Module 
  27. === Output of the program ===  
  28. 第一行是空白  
  29. Net ---- 這個是第2行了  
  30. Fans  
  31. s   
  32. QQ   
  33. group   
  34. No   
  35. is   
  36. 40797788  
  37. man  
  38. Description of the example code. In the Main() subroutine you can see 
    that two variables are declared. The second variable is a String() array that receives the results from the Private Function next.   
  39. Description of the Regex. The Function shown in the example calls 
    the Regex.Split method, which can be accessed with dot notation, with no instance necessary. 
    The second parameter to the method is a regular expression pattern.   
  40. Description of the Regex pattern. The pattern "\W+" is used, and this means "1 or more non-word characters".
     This pattern will match punctuation and spaces. Therefore, all those characters will be used as delimiters.  

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

  1. Here we see one way to Split each line in a file using File.ReadAllLines and Split.
     We have a comma-separated-values CSV file, and want to print out each value and its row number. 
    Here is the input file "example.txt". [See below]   
  2. The Split code example follows. It first reads in the file with ReadAllLines. 
    This function puts each line in the file into an array element. The example next Splits on ","c. 
    The final comment shows the output of the 
    program. 
  3. === Input file used ===  
  4. frontal,parietal,occipital,temporal  
  5. pulmonary artery,aorta,left ventricle 
  6. === Example program that splits lines (VB.NET) ===  
  7. Imports System.IO  
  8. Module Module1  
  9. Sub Main()  
  10. Dim i As Integer = 0 
  11. 'vb.net  
  12. ' Loop through each line in array returned by ReadAllLines  
  13. Dim line As String  
  14. For Each line In File.ReadAllLines("example.txt")  
  15. ' Split line on comma  
  16. Dim parts As String() = line.Split(New Char() {","c})  
  17. ' Loop over each string received  
  18. Dim part As String  
  19. For Each part In parts  
  20. ' Display to Console  
  21. Console.WriteLine("{0}:{1}", i, part)  
  22. Next  
  23. i += 1  
  24. Next  
  25. End Sub  
  26. End Module 
  27. === Output of the program ===  
  28. 0:frontal  
  29. 0:parietal  
  30. 0:occipital  
  31. 0:temporal  
  32. 1:pulmonary artery  
  33. 1:aorta  
  34. 1:left ventricle  

【編輯推薦】

  1. 介紹VB.NET繪圖方法的三個方面
  2. 你是否了解VB.NET集成開發環境
  3. 簡單談論VB.NET傳輸表空間
  4. 淺析VB.NET語言與VB語言對比
  5. 五大類VB.NET運算符全面介紹
責任編輯:田樹 來源: 樂博網
相關推薦

2010-01-19 14:50:20

VB.NET集合

2010-01-19 09:36:06

VB.NET Func

2010-01-21 14:06:03

VB.NET MyCl

2010-01-21 17:23:05

VB.NET Radi

2010-01-20 17:47:54

VB.NET注釋

2009-10-15 17:50:48

VB.NET Spli

2009-11-02 13:14:18

VB.NET函數

2009-10-27 13:34:32

VB.NET WEB服

2009-11-02 15:08:58

VB.NET Obje

2010-01-20 13:28:35

VB.NET計算數字

2010-01-18 13:12:43

VB.NET控件數組

2009-10-13 15:20:02

VB.NET使用Dra

2010-01-20 10:27:07

VB.NET隱式類型局

2009-11-03 09:48:47

VB.NET構造

2009-10-16 13:38:43

VB.NET Spli

2009-10-30 09:45:55

VB.NET Web

2009-10-28 17:08:57

VB.NET數據庫開發

2009-11-03 09:26:13

VB.NET方法

2009-10-26 18:41:05

VB.NET獲取硬盤信

2009-11-03 13:48:02

VB.NET枚舉
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲一区二区三区久久 | www.9191| 欧美日韩在线一区二区 | 91视频国产区 | 99精品视频在线观看 | 亚洲va欧美va天堂v国产综合 | 91精品国产色综合久久 | 久久久久1 | 91精品国产综合久久久久久丝袜 | a级在线免费视频 | 久久国产三级 | 欧美在线看片 | 欧美日韩高清免费 | 午夜小电影 | 一本久久a久久精品亚洲 | 久久久久一区二区三区 | 久操av在线 | 日本精品裸体写真集在线观看 | 日韩中文字幕视频在线 | 成人影院一区二区三区 | 福利社午夜影院 | 日本免费一区二区三区视频 | 天天干天天玩天天操 | 国产精品久久久亚洲 | 在线观看中文字幕一区二区 | 免费在线黄色av | 极品销魂美女一区二区 | 久久伊人影院 | 一级美国黄色片 | 久久中文视频 | 日本黄色片免费在线观看 | 91久操视频 | 69av片| 亚洲不卡视频 | 日韩一区二区视频 | 91精品一区二区三区久久久久 | 成人在线一区二区三区 | 最近中文字幕免费 | 国产精品久久久久久久久久久久午夜片 | 亚洲成人一区二区 | 精品国产乱码一区二区三区 |