String format like vb6.Format$

Hi !

I’m converting code from VB6 to XOJO.

In vb6 i use this

xFone = Format$("552122223333", "(@@) (@@) @@@@-@@@@")' Returns (55) (21) 2222-3333

in Xojo, “Format” functions only format numbers. Thera are a function to format strings?

link text

[code]The following example returns the number 3560.3 formatted as $3,560.30.

Dim s as Strings=Format(3560.3, “\$###,##0.00”)[/code]

The format should do what you are asking for, unless I misunderstood your question

Well, this isnt quite as flexible as that format statement, but it looks like your needs are pretty specific.

Try this:

Function FormatVB6(inp as string) As string dim s1 as string if len(inp) <> 12 then s1 = right("000000000000" + inp,12) else s1 = inp end if return "(" + left(s1,2) + ") (" + mid(s1,3,2) + ") " + mid (s1,5,4) + "-" + right(s1,4)

called like this:

xFone = FormatVB6(“552122223333”)

End Function

Well, since your “string” is actually a number you can certainly use Format to do what you want:

Function FormatString(value as string, fmt as string) As String
dim v() as string = split(value, “”)
dim f() as string = split(fmt, “”)
dim pos as integer

for i as integer = 0 to f.Ubound
if pos > v.Ubound then Exit
if f(i) = “@” then
f(i) = v(pos)
pos = pos + 1
end if

Return Join(f, “”)

End Function