Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format a text string

Status
Not open for further replies.

revilord

Programmer
Oct 2, 2003
64
I am trying to format a text string retrieved from a recordset.
I want to turn
A12345678911
B123456
C1234
to
A123-4567-8911
B123-456
C123-4

I Tried format(rs.Fields(1), @@@@-@@@@-@@@@)
but I get
[tt]
A123-4567-8911
- B12-3456
- C-1234
[/tt]
Not exactly what I want
 
Perhaps try some string manipulation on it:

[tt] left$(format(rs.Fields(1) & "000000000000", @@@@-@@@@-@@@@), len(rs.Fields(1))[/tt]

Roy-Vidar
 
And this ?
Trim(Replace(Format(rs(i) & " ", "@@@@-@@@@-@@@@"), "- ", ""))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV's solution is a bit better since data was getting cut off with len(rs.Fields(1)) since this doesn't allow for the added "-"'s
 
seems like it could be simplified by forcing left-fill with ! and using & which doesn't add a space:
[tt]
strFormatted = Replace(Format(rs(i), "!&&&&-@&&&-@&&&"), "- " , "")
[/tt]

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top