Click here to Skip to main content
14,270,361 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,
I am reading a Microsoft Office Word text from a vb.net app, and then storing the formatted string in another ans file. Somewhere in this file I am finding 4 unreadable characters. I went in debug mode and I found out that the Asc code of each of these characters is 32 !!
Normally this is the space code, although I used:
rettext = Replace(rettext, " ", "" )
and
rettext = Replace(rettext, Asc(32), "" )
and
rettext = Trim(rettext)

but still the rettext variable is not changed and have the same length!!

Anyone have an idea what to do ??
Thx in advance.
Posted
Updated 24-Oct-13 4:53am
v2
Comments
saguptamca 24-Oct-13 10:19am
   
I understand the issue. But can u Pls provide original sample code to solve the issue.
saleem_deek 24-Oct-13 10:52am
   
l = l.Replace(Chr(32), "")
l = l.Replace(" ", "")
l = Trim(l)
ledtech3 24-Oct-13 10:49am
   
Without more code to view where you are checking the lenth.
You may be only returning the original variable length not the trimmed length.
you may try to asign the output of the trim /replace function to another variable and check the length of that.
saleem_deek 24-Oct-13 10:52am
   
this is my code:
l = l.Replace(Chr(32), "")
l = l.Replace(" ", "")
l = Trim(l)
ledtech3 24-Oct-13 11:04am
   
you are using all 3 at the same time?
I would think it should be throwing some kind of error.

I think part of the problem is you are baisicly resseting the output to what the input was.
without being able to step thru it see what it is doing.
use a different variable name for the output as you do for the input and see what happens.
saleem_deek 24-Oct-13 11:19am
   
I did try, but still same problem.
I think we should think of that this string is originally read from a word file,
maybe this is the key to the problem, but I cannot figure out what it might be !
ledtech3 24-Oct-13 11:27am
   
Something like this.
Dim inputStr As String = tbInput.Text
Dim output As String
output = Replace(inputStr, " ", "")
tbOutput.Text = output

Edit:
Input is: This Text Has space
Output is: ThisTextHasspace
Sergey Alexandrovich Kryukov 24-Oct-13 11:24am
   
Just one note: ASCII? In .NET? Do be serious. Nearly all modern software supports Unicode now, and in .NET, there is no a way to limit user input by ASCII. Any user input beyond, and your ASCII goes nowhere. Even in pure English-US culture, texts following proper typographic requirements use Unicode to the extents well beyond ASCII...
—SA
Sergey Alexandrovich Kryukov 24-Oct-13 11:35am
   
Replace?! What is that, a method of what?
—SA
saleem_deek 24-Oct-13 11:44am
   
hahaha.. what's the matter Sergey why so mad ?!!
I'm used to vb6 for 4 years and I'm trying to move to vb.net so take it easy on me and help me
Now I see that u answered ;)

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

To remove blank spaces from a string, use:
rettext = rettext.Replace(" ", string.Empty);


Please see: http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx[^].

(Always use string.Empty instead of "", by a number of reasons.) It should work. If the string is not changes (are you 100% sure?), it simply means that you don't have blank space characters in your input string. Note that many other characters may only look similar to the blank space, but be something else: Em space, En space, Non-breakable space, Tab, and more. I hope you typed " " using blank space, not something else. Look at your input string carefully.

And of course, don't try to use ASCII in .NET, please see my comment to the question. More exactly, you can use it, but only if you can, by some special reasons, guarantee that no input will be beyond ASCII. And learn how Unicode works, it is less trivial than many think.

—SA
   
v2
Comments
ledtech3 24-Oct-13 11:50am
   
That worked fine in my test sample.
Just had to remove the semicolon at the end and "Dim" it up for VB.Net
Thanks for another way to do it.
Sergey Alexandrovich Kryukov 24-Oct-13 13:11pm
   
My pleasure.
Good luck, call again.
—SA
saleem_deek 24-Oct-13 11:50am
   
I will learn about Unicode, I'm sure this is the issue here.
Thanks a lot for answering :).
Sergey Alexandrovich Kryukov 24-Oct-13 13:12pm
   
Certainly you will need it. In case of doubt, you are very welcome to ask new questions. :-)
—SA
saleem_deek 24-Oct-13 11:51am
   
Especially that the source of this string is a bookmark in a Word file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100