Solved

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

Posted on 2007-03-20
4
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

628 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