Jump to content

Wanting to delete invalid charachter

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
stackemevs

stackemevs

    Newbie

  • Members
  • PipPip
  • 17 posts
Hi,

I am trying to copy/import a string leaving out any occasional invalid characters. I am currently trying:

Dim HexKill As Long

For HexKill = 1 to 50
sline = Replace(sline, Chr(HexKill), "")
Next

Which has appeared to work sometimes, but not others. I don't think quite gives the program the freedom it needs to run correctly. Also thought of Substitute and VLookup, but have not got them working correctly.

Any suggestions much appreciated,
Ta.

#2
Ray Tawil

Ray Tawil

    Programmer

  • Members
  • PipPipPipPip
  • 108 posts
Hello stackemevs,

You can use the embedded utility provided by vb.net

it's string.replace("original char","replacement char")

as following in this example i did:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim str As String

        str = TextBox1.Text


        TextBox1.Text = str.Replace("d", "r")


    End Sub


#3
stackemevs

stackemevs

    Newbie

  • Members
  • PipPip
  • 17 posts
Hi rabih tawil,

Thanks, that looks similar to other loops I have considered to check and replace characters. Any idea how I can select ranges of hex characters I do or don't want to select/replace.

#4
Ray Tawil

Ray Tawil

    Programmer

  • Members
  • PipPipPipPip
  • 108 posts
there is no way to do it without loops,
as i can see it is useless to remake what Microsoft has provided with.
anyway about your hex chars questions, please can you be clearer because i didn't get what you exactly need
Share your Knowledge, It's one way to achieve immortality.
Video Tutorial Channel

#5
stackemevs

stackemevs

    Newbie

  • Members
  • PipPip
  • 17 posts
Hi, below is an example about data being read into a file, a square has been added to the string after harddrive, it is only vary rare, and appearing random as to where and when:

"Western digital harddrive(small square put here) 750Gb"

I'm looking for a very small [and basic] loop which could check and delete it without slowing input down.

I have had to type in "Small square put in" as copied symbol in, but not displayed here.

Edited by stackemevs, 08 February 2010 - 04:40 AM.
Character not copied in


#6
Ray Tawil

Ray Tawil

    Programmer

  • Members
  • PipPipPipPip
  • 108 posts
when you say data being read into a file, you mean there is a GUI & the user is entering in it & whenever he hits save it is saved into a .txt file?
if that so then rather of handeling at the save time which looks that you hate because it is time consuming, i will assume that your user is typing into a textbox, if that so, then check this blog about preventing certain types of chars, you can specify the characters that you want to be allowed to get typed in the textbox & then all your pain is gone away,
Make a Textbox that accepts only numbers | Rabih Tawil

if that is not the case please specify your cases clearer so i can help.
Share your Knowledge, It's one way to achieve immortality.
Video Tutorial Channel

#7
stackemevs

stackemevs

    Newbie

  • Members
  • PipPip
  • 17 posts
Hi, sorry if not clearer. No it is a set of macros I have created, which is reading data in from different formats, .txt, .jes .dat .prn, mainly .xls. These may be tab or space deliminated. The data coming in may be in all formats, char, string, long etc. The macro is then taking data from a couple of relevant fields and putting it as strings into another txt file. Maybe not standard use for Excel VBA but it does it very well.

Very occasionally I get the 'square' invalid character at the end of a char string. If I can create a very quick and "easy" piece of code which can check the characters being accepted.

Having a very quick look at the link above I think this is the sort of thing I have been considering, and may try it later. The concern was that my files in could contain over a 100,000 data sets, and I didn't want to slow input and processing down. For this I did think maybe checking for hexdecimal characters would be quicker.

Thanks