Solved

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

Posted on 2007-03-20
4
277 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
Comment Utility
Try using either one of these:

s11 = value.GetString(d22).Trim

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

Author Comment

by:moellert
Comment Utility
neither works
0
 
LVL 34

Accepted Solution

by:
Sancler earned 125 total points
Comment Utility
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
Comment Utility
That did the trick.
I was Replace (s11, Char(0),"")
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

10 Experts available now in Live!

Get 1:1 Help Now