Results 1 to 4 of 4

Thread: Having equal spaces in a string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    Scotland
    Posts
    68

    Angry

    I am having a problem, I have a sting and i want to remove the extra spaces from the line so that there is only one space bar key press between each word. ie

    strAns = E 3 10:53 1:z1100 77 sqfp80 180 -6 -9 1800 1 qp242a-17 Missing

    I would like this to be;

    strAns = E 3 10:53 1:z1100 77 sqfp80 180 -6 -9 1800 1 qp242a-17 Missing


    Any help is appreciated, I have tryed the replace function but cannot get the syntax right
    Why can't every day be Saturday ??

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    How about using my function nodoublespaces:
    Code:
    Function nodoublespaces(str As String)
        Dim a() As Byte, s&, n&, v As Boolean
        a = StrConv(str, vbFromUnicode)
        For n = 0 To UBound(a)
            If a(n) = 32 And v Then s = s - 1
            If s <> n Then a(s) = a(n)
            v = a(s) = 32
            s = s + 1
        Next n
        ReDim Preserve a(s)
        nodoublespaces = StrConv(a, vbUnicode)
    End Function
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    Scotland
    Posts
    68
    thanks mate I will give it a try !!
    Why can't every day be Saturday ??

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    Scotland
    Posts
    68
    Thanks Kedaman it worked perfectly


    Murtagh
    Why can't every day be Saturday ??

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