WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

String Manipulation

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Format Number Strings UDF

Keywords: 	 Format Number Strings UDF  udfStrTranslate

; This UDF can format number-strings (like phone numbers) and also re-arrange
;the ordering

#DefineFunction udfStrTranslate (sString, sTableIn, sTableOut, sPad)
   If (sTableOut=="") Then If (sTableIn=="") Then Return (StrUpper(sString))
   If (sPad=="") Then sPad = " "
   aArray = ArrDimension(256)
   For i=0 To 255
      aArray[i] = i
   Next
   iLenString = StrLen(sString)
   iLenIn = StrLen(sTableIn)
   sTableOut = StrFix(sTableOut,sPad,iLenIn)
   iLenOut = StrLen(sTableOut)
   For i=1 To iLenIn
      aArray[Char2Num(StrSub(sTableIn,i,1))] = Char2Num(StrSub(sTableOut,i,1))
   Next
   sOut = ""
   For i=1 To iLenString
      sOut = StrCat(sOut,Num2Char(aArray[Char2Num(StrSub(sString,i,1))]))
   Next
   Drop(aArray)
   Return (sOut)
   ; Detlev Dalitz.20020219
#EndFunction


; --- test ---
:format_numberstring
sMsgTitle = "Demo udfStrTranslate (sString, sTableIn, sTableOut, sPad)"

;sString is the format code.  The alpha letters are placeholders for the numbers.
;It more or less shows what the forrmated string should look like
sString   = "(abc) defg-hijk"
;sTableIn must match up with sDataIn to show where the numbers should be placed.
;almost always the numbers are already in the correct order, but you can
;change that
sTableIn  = "abcdefghijk"
;And sDataIn is the numeric string you wisht to format
sDataIn   = "12345678901"
;sPad is the character to use if the sDataIn string is shorter than sTableIn
sPad = " "

sTrans = udfStrTranslate (sString, sTableIn, sDataIn, sPad)

sMsgText = StrCat(sString,@CRLF,sTrans)
Message(sMsgTitle,sMsgText)

Exit




Article ID:   W15763
File Created: 2003:05:13:11:29:58
Last Updated: 2003:05:13:11:29:58