Solved

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

Posted on 2007-03-20
4
280 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now