Results 1 to 3 of 3

Thread: Need help with removing spaces

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Need help with removing spaces

    Hi, I have some strings which have spaces at the end of them. I want to remove the spaces by going backwards. My code:

    Code:
    For num = s.Length To 0 Step -1
        If Mid(s, num - 1, num) = " " Then
            Console.WriteLine("Removing space")
            s = s.Remove(num - 1, 1)
        Else
            Exit For
        End If
    Next
    My code can't delete the characters and doesn't output "Removing space". Can anyone help me?

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Re: Need help with removing spaces

    Anyway, I fixed this by code:

    Code:
    Dim lastWord As String = s.Split("+").Last
    s = s.Replace(lastWord, "")

  3. #3
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Need help with removing spaces

    My Github - 1d3nt

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width