Solved

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

Posted on 2004-08-09
5
621 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

737 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