Page 1 of 1

VBS returns localized TRUE/FALSE

Posted: 03 Jul 2025 01:36
by miskox
Windows 10, 64 bit, Slovenian.

I would like to check if a variable has only numeric characters, is date and if it's length is exactly 13 characters. I have this:

Code: Select all

@echo off
set numbe=1234567890123
set datte=2024-08-01
>tmp.vbs  echo n=isnumeric("%numbe%") : d=isdate("%datte%") : L=len("%numbe%")
>>tmp.vbs echo WScript.Echo n ^& "#" ^& d ^& "#" ^& L

For /F "tokens=1,2,3 delims=#" %%A In ('CScript tmp.vbs //NoLogo') do (
	set num=%%A
	set isd=%%B
	set len=%%C
)

echo %num% %isd% %len%

set num=XXX
set isd=XXX
set len=XXX

>tmp.vbs  echo if isnumeric("%numbe%") then n=1 else n=0
>>tmp.vbs echo if isdate("%datte%")    then d=1 else d=0
>>tmp.vbs echo if len("%numbe%")=13    then L=1 else L=0
>>tmp.vbs echo WScript.Echo n ^& "#" ^& d ^& "#" ^& L

For /F "tokens=1,2,3 delims=#" %%A In ('CScript tmp.vbs //NoLogo') do (
	set num=%%A
	set isd=%%B
	set len=%%C
)

echo %num% %isd% %len%

if exist tmp.vbs del tmp.vbs
Output:

Code: Select all

d:\ch.cmd
Resnično Resnično 13
1 1 1
d:\>
As you can see TRUE is written as Resnično (localized to Slovene).

To avoid problems with localization I am using IF to change that to 1 or 0 so I check for 0 and 1 in the variables.

Running .vbs takes a lot of time. More efficient way to use first option instead of IF statements?
Or even completely different approach?

I have .txt files with many records as this:

Code: Select all

0123456789012;2025-08-01
and I want to make sure it starts with a 13-digit number followed by a valid date.

Thanks.
Saso

Re: VBS returns localized TRUE/FALSE

Posted: 03 Jul 2025 04:38
by miskox
I also had this solution:

Code: Select all

findstr /R "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\;" file.txt>tmp1.tmp
findstr /R "\;[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]$" tmp1.tmp>tmp2.tmp
but Dave writes here https://stackoverflow.com/questions/263 ... 15#8767815 about this [0-9].

So using [0123456789] might be better.

I then just use the dates, remove duplicates (there are lots of duplicates) and check for date validation separately.

Saso

Re: VBS returns localized TRUE/FALSE

Posted: 03 Jul 2025 09:56
by aGerman
You can cast the boolean values in VBS already (using the cint function). This way FALSE becomes 0 and TRUE becomes -1.

This said, you should really make the vbs scan the whole file at once. Calling cscript for every line will be horribly slow. Or use JREPL.bat or any other tool with better regex support than findstr.

Steffen

Re: VBS returns localized TRUE/FALSE

Posted: 03 Jul 2025 22:31
by miskox
Thank you Steffen.

Saso