Remove white space in a string : Char Function « Data Type « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Data Type » Char Function 
2.14.5.Remove white space in a string
Public Class Tester
    Public Shared Sub Main
        Dim source As String = _
            Space(17"This    string    had " & Chr(12& _
            StrDup(5, Chr(9)) "extra whitespace. " & Space(27)
        Dim thisIsWhiteSpace As Boolean
        Dim prevIsWhiteSpace As Boolean
        Dim result As New System.Text.StringBuilder(source.Length)
        Dim counter As Integer

        For counter = To source.Length - 1
            prevIsWhiteSpace = thisIsWhiteSpace
            thisIsWhiteSpace = Char.IsWhiteSpace(source.Chars(counter))
            If (thisIsWhiteSpace = FalseThen
                If (prevIsWhiteSpace = TrueAndAlso _
                   (result.Length > 0Then result.Append(Space(1))
                result.Append(source.Chars(counter))
            End If
        Next counter
        Console.WriteLine(result.ToString())
    End Sub


End Class
This string had extra whitespace.
2.14.Char Function
2.14.1.Passing Char values to Val
2.14.2.Char: IsLetter, IsControl, IsDigit, IsLetterOrDigit, IsLower, IsNumber
2.14.3.Char: IsPunctuation, IsSeparator, IsSymbol, IsUpper, IsWhiteSpace
2.14.4.Char.IsDigit
2.14.5.Remove white space in a string
2.14.6.Char.ToUpper
2.14.7.ChrW
2.14.8.Demonstrates IsWhiteSpace.
2.14.9.Char.Equals.
2.14.10.Output ControlChars.Tab
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.