Remove square character

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

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

Thanks.
Mark
 
Mark said:
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
 
Mark said:
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.
 
:
: 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top