Mega Code Archive

 
Categories / VB.Net / Data Types
 

Is Punctuation and Is WhiteSpace

Module Example    Public Sub Main()       Dim s1 As String = "This string consists of a single short sentence."       Dim nWords As Integer = 0       s1 = s1.Trim()             For ctr As Integer = 0 To s1.Length - 1          If Char.IsPunctuation(s1(ctr)) Or Char.IsWhiteSpace(s1(ctr))              nWords += 1                        End If          Next       Console.WriteLine("The sentence{2}   {0}{2}has {1} words.",                         s1, nWords, vbCrLf)                                                                         End Sub End Module