2 regex or not 2 regex?

boten

Active Member
Licensed User
Longtime User
Being a complete "regex illiterate" I'd like suggestions on how to capitalize a string, something like

Code: Copy
result=Capitalize(source,delimiters)

where:
source is any string containing numbers, commas, $, (, - etc...

and delimiters is a string of characters delimiting words e.g: - /()| ?$%0123456789

Code: Copy
s="this is worth 50$of dead-junk"
s2=Capitalize(s,"01234567890 $-")
will return: "This Is Worth 50$Of Dead-Junk""
 
I know nothing about regularExrpessions, yet I think what you ask can be easily accomplished by checking the previous char of a char and setting the latter to uppercase if the previous one is one of the delimiters. You just loop through your string and use the charAt function.
 
Upvote 0
Yes, that's the obvious solution. I wonder if using Regex would be faster (for many long strings).
 
Upvote 0
Regex will not be faster (assuming that you write your code correctly). Any method will need to go over all the characters.
This is very true. Sometimes we all tend to think that an in-built method will be faster, and we don't see the obvious (of course not all the time).
 
Upvote 0
Back
Top