Results 1 to 5 of 5

Thread: [RESOLVED] Function to remove leading & trailing spaces in a text box?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    326

    Resolved [RESOLVED] Function to remove leading & trailing spaces in a text box?

    Is there a way to write a function that can remove the leading & trailing spaces as well as extra spaces between words as well as in the below example from a Text Box?

    spaceVertexspace spaceNospace.space 365 (space22 Pairsspace)

    Result: "Vertex No. 365 (22 Pairs)"

    I need a function to remove such extra spaces like leading & trailing and in brackets' spaces from a Text Box.
    Last edited by VS2013; Jan 11th, 2018 at 11:38 AM.

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,041

    Re: Function to remove leading & trailing spaces in a text box?

    Hi,

    what have you tried sofar ?

    take a look at Regex Replace
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Function to remove leading & trailing spaces in a text box?

    Try this
    Code:
        Private Function RemoveExtraSpaces(strText As String) As String
            Return String.Join(" ", strText.Split({" "}, StringSplitOptions.RemoveEmptyEntries)).Replace("( ", "(").Replace(" )", ")")
        End Function
    Last edited by 4x2y; Jan 11th, 2018 at 04:03 PM.



  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    326

    Re: Function to remove leading & trailing spaces in a text box?

    Great help. Thanks.

  5. #5
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: [RESOLVED] Function to remove leading & trailing spaces in a text box?

    You may also consider replacing "space." with ".", i have just noticed it now!



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