Solved

How to get rid of spaces in a string (seams Trim$ does not work)?

Posted on 2007-03-20
4
285 Views
Last Modified: 2010-05-18
I am using the following code:

Dim value As System.Text.Encoding
value = System.Text.Encoding.Default
Dim d111 As Byte()
d111 = value.GetBytes(adminusername_enc)
Dim d22(133) As Byte
NFuseEncode(d111, d111.Length, d22)
Dim s11 As String
s11 = Trim$(value.GetString(d22))
Print(a, "Adm-Username=" & s11)

NFuseEncode is taken from a seperate .dll. No need to think about.

As you can see the variable "d22" is a 133 characters long byte. When passing this in the string "s11" the output is always "Adm-Username=xxxx                                                 " with 133 - xxxx spaces at teh end.
I thought the Trim$ or RTrim$ function would kill all spaces but thats not working.

How do I get rid of all spaces at the of "s11"?
0
Comment
Question by:moellert
  • 2
4 Comments
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 18758430
Try using either one of these:

s11 = value.GetString(d22).Trim

s11 = Replace(value.GetString(d22), " ", "")
0
 
LVL 2

Author Comment

by:moellert
ID: 18758767
neither works
0
 
LVL 34

Accepted Solution

by:
Sancler earned 125 total points
ID: 18762714
The various versions of .Trim will only get rid of spaces AT THE END (or the beginning).  My guess here is that at least some of what look like spaces in value.GetString(d22) are not spaces.  My original guess would have been that the string was just null-terminated: that is, that the last character in it was Chr(0).  Then, any spaces would not have been at the end of it.  But that you say that

s11 = Replace(value.GetString(d22), " ", "")

doesn't work suggests it may be more extensive than that.  So what I suggest you do is run the raw string through something like this

        Dim s As String = value.GetString(d22)
        For i As Integer = 0 To s.Length - 1
            Debug.Write(Asc(s.Substring(i, 1)) & " ")
        Next
        Debug.WriteLine("")

so you can see what, precisely, it is made up of.  Then you can use appropriate methods - e.g. .Replace with other arguments - to get rid of what you don't want.

Roger
0
 
LVL 2

Author Comment

by:moellert
ID: 18764193
That did the trick.
I was Replace (s11, Char(0),"")
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question