Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Check string format

 Keywords: Check string format 

Sample:

#DefineFunction F_CheckString(InputStr, FormatStr)
	StrFLengte = 0
	StrILengte = 0
	Result = @FALSE
	ReturnResult = @TRUE
	InputStr = StrUpper(InputStr)
	FormatStr = StrUpper(FormatStr)
	StrFLengte = StrLen(FormatStr)
	StrILengte = StrLen(InputStr)
	
	; Lets check the length of both strings first!
	If StrFLengte == StrILengte ; is the stringlength equal?
		ArrayLength = StrILengte+1 ; we must have 1 more because strings start at zero and strsub starts at position 1
		MatchString = ArrDimension(ArrayLength)
		MatchString[0] = " " ; this guy wont be used 
		
		;now we create a formatstring based on the inputstring where every alfanum character will be replaced by an A and
		;any numeric characters by an 1
		For x=1 to StrILengte ; Length of inputstring 
			result = @FALSE
			result = IsNumber(StrSub(InputStr,x,1)) ; Is this character a number?
			If result ; yes it is a number
				MatchString[x] = "1" ;build our input format string, we discovered a number
			Else
				MatchString[x] = "A" ;build our input format string, we discovered a alfanumeric character
			Endif
		Next
		
		For x=1 to StrILengte
			If MatchString[x] != StrSub(FormatStr,x,1)
				ReturnResult = @FALSE ; We discovered a non valid type
				break
			Endif
		Next
		
	Else
		ReturnResult = @FALSE ; the stringlength of the input string and format string are not equal so the inputstring isnt valid
	Endif
	
	return ReturnResult
#EndFunction
;*******************************************************************
;***** End of function F_CheckString 
;*******************************************************************


ret = F_CheckString("deana1234", "aaaaa1111")
if ret == @true
	Message("Check string format","String matches specified format")
else
	Message("Check string format","String does not match specified format")
endif
exit