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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert ThisIsAString to This Is A String

Status
Not open for further replies.

Wickersty

Programmer
Nov 13, 2002
51
0
0
US

Hi folks,

I have a bunch of strings that are missing spaces, and I want to insert spaces every time I encounter a capital letter. I'm having a bit of a pickle trying to figure this out. Could someone lend some advice?

Many thanks.

An example is: "AWarmDay"

I want to convert to "A Warm Day"

thnx,

Jeff
 
Looks like you would have to loop throught the string one character at a time and find the capitals.

When found you would need to take that letter attach a space to the begining and keep going.

Basically you would be rebuilding the string one character at a time.

I don't think REFind or REReplace will do the trick this time. I don't think they will tell you the specific character returned, and would simply just replace the found character with another.
 
But how do you determine what case a character is? LCase and UCase are functions to convert a character to a case, but they don't tell you what case a character is before hand...

that's where I'm stuck.
 
Try...

Code:
<cfset tist = "ThisIsAString">
#ReReplace(tist,"[A-Z]"," \1","ALL")#

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
<cfset tist = "ThisIsAString">
#ReReplace(tist,"[A-Z]"," \1","ALL")#

That gives me:

his s tring

It removes cap letters and replaces them with spaces. I don't want to lose the cap letters, I just want to insert a space before each cap letter.
 
Duh! Try this, sorry.

Code:
<cfset tist = "ThisIsAString">
#ReReplace(tist,"([A-Z])"," \1","ALL")#

That gives me:

his s tring

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Right on. That worked perfectly. Thanks a million!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top