4
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by vbprogrammer1
0

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.
0

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

0

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
0
Dim str = "12     44.55     66.44"
Dim result = String.Join(" ", str.Split(New Char() {" "}, StringSplitOptions.RemoveEmptyEntries))
0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.