Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Strip Characters from String?

Engaged ,
Oct 15, 2008 Oct 15, 2008
Hi,

How can I strip off some characters from the end of a string? I am not very good at regular expressions but perhaps I may not need one? Here is the data

first_name_510
last_name_2267

I need a function that will strip off everything from the right including the underscore. I should be left with the below:

first_name
last_name

Any help highly appreciated

Regards
573
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 15, 2008 Oct 15, 2008
if it is always an underscore, and always the last one, this should do
the trick:
#left(string, len(string)-len(listlast(string, "_"))-1)#

string is assumed to be the variable holding your text

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 15, 2008 Oct 15, 2008
Or more elegantly,

#ListDeleteAt(mystring,listLen(mystring,"_"),"_")#
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 15, 2008 Oct 15, 2008
LATEST
just for reference, if you want to see what a simple regular expression version might look like:
#REReplace(yourstring, "(.+_.+)_.+", "\1")#
but I think the best way is to treat it like a list with an underscore delimiter, like Fernis.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources