Skip to main content
Inspiring
October 15, 2008
Question

Strip Characters from String?

  • October 15, 2008
  • 2 replies
  • 641 views
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
    This topic has been closed for replies.

    2 replies

    Fernis
    Inspiring
    October 15, 2008
    Or more elegantly,

    #ListDeleteAt(mystring,listLen(mystring,"_"),"_")#
    October 15, 2008
    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.
    Inspiring
    October 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/