milsykor
7th April 2004, 10:25
I would like to have the user name splitted into two parts and therefore I tried to use scan.string in following way :
long ret
string A,B,C(20)
tt.user(logname$, user.name)
c = $user.name
ret = string.scan(c,"%s, %s",A,B)
name = $B & " " & $A
Does it make any sense ?
thanks in the advance
RobertB
7th April 2004, 10:35
Looks like you're trying to change a name like "Duck, Donald" to "Donald Duck". You're nearly there - try this (assuming you already have logname$):
long ret
string A(30), B(30), user.name(60), new.name(60)
tt.user(logname$, user.name)
ret = string.scan(user.name, "%s, %s", A, B)
new.name = B & " " & A
HTH,
Robert
milsykor
7th April 2004, 15:47
I have traced the variables A,B which should contain the name in two parts, e.g. John and B=Lennon, but the result differs from my expectation because whole name is involved in A=John Lennon . Why ?
RobertB
7th April 2004, 16:54
Then the original logname$ (probably) contains no comma.
The format-argument "%s, %s" tells string.scan to expect that the string stored in the variable user.name has the structure "yyyyyyyyyyyyy, xxxxx", as in "Lennon, John" - where the two name-parts are separated explicitly by a comma plus a space.
But if the comma+space are missing, then string.scan scans the string up to the end, still looking for the comma, and stores what it has scanned into the the first field only...
Perhaps your original string is like "John Lennon" (or "Lennon John"), in which case use "%s %s" as your format-argument.
HTH