Hi,

Can anyone tell me how to remove spaces in a line which contains more spaces in vb.net.

Eg

12 25.53 35

It should be read as 12 25.53 35

Thanks
VRP

Confusing to understand since both, the line with spaces and the line that should be read as, contain spaces.:D

See if this helps otherwise.

Dim sTemp As String = "12 25.53 35" '// your String.
        sTemp = sTemp.Replace(" ", "") '// replace space with nothing.
        MsgBox(sTemp) '// display result.

Sorry for the confusion. I entered with 12 spaces between 12 and 25.35 and another 12 spaces between 25.53 and 35. But the system posted the message as 12 25.53 35 (concatenated with 1 space between 12 and 25.35 and similarly with a space between 25.53 and 35.
I could read with a single space between the number and replace with nothing / empty but could'nt do with more spaces.

Thanks for your reply.

VRP

Its not a very elegant solution, but it should work for what you need.

Dim sTemp As String = "12             25.53            35"
        Try
            For I = 1 To sTemp.Length - 1
                If sTemp.Substring(I, 1) = " " Then
                    Dim SpaceCTR = 0
                    For L = I To sTemp.Length
                        If sTemp.Substring(L, 1) <> " " Then Exit For
                        SpaceCTR += 1
                    Next
                    If SpaceCTR > 1 Then
                        sTemp = sTemp.Remove(I, SpaceCTR - 1)
                    End If
                End If
            Next
        Catch ex As System.ArgumentOutOfRangeException
        End Try
Dim str = "12     44.55     66.44"
Dim result = String.Join(" ", str.Split(New Char() {" "}, StringSplitOptions.RemoveEmptyEntries))

Thank you very much for the reply.
I could accomplish my task with
"result = String.Join(" ", str.Split(New Char() {" "}, StringSplitOptions.RemoveEmptyEntries))"

Thanks
VRP

This question has already been answered. Start a new discussion instead.