?
Solved

how to recognize non-English characters in a string in VBScript

Posted on 2004-08-09
5
Medium Priority
?
638 Views
Last Modified: 2012-05-05
I have a VBScript to read lines of text from another file. Due to the nature of how the other file is produced, it contains some weird characters among other useable English words.

I want to read a line, analyze each character and get rid of any non-English or numeric characters and then write the text to another file.

Right now I am thinking to convert the string to an array then analyze each element of the array to see if it is any English letter or number. If so keep it else discard it. But I am not sure how to do it.

In C++, I remember, I could convert the character to Int and that Int will be the ASCII value of that character. But it won't let me do this in VBScript. So please help me out here.

Thanks!

BTW, if you could provide an even easier method to get rid of non-English and non-numeric characters from a string of text for VB Script, it would be even better.
0
Comment
Question by:UltimateApocalypse
[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
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 280 total points
ID: 11762022
Hi,

A-Z = 65-90
a-z = 97-122
.-, = 44-46

assuming you have text file stored in variable strData, the code would be something like this:

Dim i
For i = 0 To 255
    If Not (64 <= i And i <= 90) And Not (97 <= i And i <= 122) And Not (44 <= i And i <= 46) And i <> vbCrLf And i <> 32 Then
        strdata = Replace(strdata, Chr(i), "")
    End If
Next

Wscript.Echo strData
0
 
LVL 19

Assisted Solution

by:Shauli
Shauli earned 120 total points
ID: 11762468
'Something like that would get rid of all "non-enlish non-numeric" unwanted characters.
'the group of characters you do want are between 32(spca) and 122(z):

For c = 0 To 31
    myLine = Replace(myLine, Chr(c), "")
Next
For c = 123 To 255
    myLine = Replace(myLine, Chr(c), "")
Next
MsgBox myLine

S
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11762520
Yeah well thats same as my code except that my allows only "A-z", ",.-", " ", clrf :))

Darko
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11762562
DarkoLord , you are absolutely right. I just extended your approach to include characters like space, dash, colon etc..   :)

S
0
 

Author Comment

by:UltimateApocalypse
ID: 11763596
Thanks for the help, so the keyword here is Chr.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 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