boten Active Member Licensed User Longtime User Dec 19, 2012 #1 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""
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""
Mark Read Well-Known Member Licensed User Longtime User Dec 19, 2012 #2 Hallo, have a look at the string functions from Margret http://www.b4x.com/forum/basic4android-getting-started-tutorials/10365-string-functions.html#post57671 Regards Upvote 0
Hallo, have a look at the string functions from Margret http://www.b4x.com/forum/basic4android-getting-started-tutorials/10365-string-functions.html#post57671 Regards
mc73 Well-Known Member Licensed User Longtime User Dec 19, 2012 #3 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
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.
boten Active Member Licensed User Longtime User Dec 19, 2012 #4 Yes, that's the obvious solution. I wonder if using Regex would be faster (for many long strings). Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Dec 21, 2012 #5 Regex will not be faster (assuming that you write your code correctly). Any method will need to go over all the characters. Upvote 0
Regex will not be faster (assuming that you write your code correctly). Any method will need to go over all the characters.
mc73 Well-Known Member Licensed User Longtime User Dec 21, 2012 #6 Erel said: Regex will not be faster (assuming that you write your code correctly). Any method will need to go over all the characters. Click to expand... 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
Erel said: Regex will not be faster (assuming that you write your code correctly). Any method will need to go over all the characters. Click to expand... 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).