Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-20
4
Medium Priority
?
289 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

715 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