Solved

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

Posted on 2004-08-09
5
600 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
  • 2
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 70 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 30 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now