By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,854 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,854 IT Pros & Developers. It's quick & easy.

Remove square character

P: n/a
I need to remove a square character from a text file. How can I locate a
square character and remove it?

Thanks.
Mark
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Mark wrote:
I need to remove a square character from a text file. How can I locate a
square character and remove it?

Thanks.
Mark


Define "square character" are you referring to any character that is
not human readable?

Step 1. Read in one Character
Step 2. Check if Character is in your allow list. (You can use
Char.IsDigit and such)
Step 3. Store the character whereever you want.

Chris
Nov 21 '05 #2

P: n/a
"Mark" <mn******@neb.rr.com> wrote in message
news:uK****************@TK2MSFTNGP10.phx.gbl...
I need to remove a square character from a text file.
How can I locate a square character and remove it?


No idea which is the "square" character, but here's a fragment to
trash all the spaces :

Dim reader as New System.IO.StreamReader( "file" )
Dim sData as String _
= reader.ReadToEnd()
reader.Close()

sData = sData.Replace( " ", "" )

Dim writer as New System.IO.StreamWriter( "file", False )
writer.Write( sData )
writer.Close()

And yes; it /does/ read the entire file into a String, do a Replace and
write the whole lot back again; even in the Brave New World that is
(or was) ".Net", you /still/ can't zap and reshuffle individual bytes in a
sequential disk file directly - which is probably a Good Thing ;-)

HTH,
Phill W.
Nov 21 '05 #3

P: n/a

"Mark" <mn******@neb.rr.com> wrote in message
news:uK****************@TK2MSFTNGP10.phx.gbl...
:
: I need to remove a square character from a text file. How can I
: locate a square character and remove it?
:
: Thanks.
: Mark
We need more context than this before we can give you a meaningful
answer, but very often unreadable (i.e.: control) characters are
rendered as boxes in some text readers. I'm assuming that is what you
are looking at in which case remove any characters that have an ASCII
value less than 32 (space). On approach (and not necessarily the best
for your needs) would be:

Dim s As String = <some value containing control chars>
Dim ndx As Integer
Dim c As Char

With New System.Text.StringBuilder
For ndx = 1 To Len(s)
c = Mid(s, ndx, 1)
If Asc(c) < 32 Then
.append(c)
End If
Next
s = .ToString
End With


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.