case insensitive lstrip function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kelie

    case insensitive lstrip function?

    Hello,

    Is there such a function included in the standard Python distribution?
    This is what I came up with. How to improve it? Thanks.

    def lstrip2(s, chars, ingoreCase = True):
    if ingoreCase:
    s2 = s.upper().lstri p(chars.upper() )
    return s[len(s)-len(s2):]
    else:
    return s.lstrip(chars)
  • Marc 'BlackJack' Rintsch

    #2
    Re: case insensitive lstrip function?

    On Fri, 28 Mar 2008 15:48:09 -0700, Kelie wrote:
    Is there such a function included in the standard Python distribution?
    AFAIK not.
    This is what I came up with. How to improve it? Thanks.
    >
    def lstrip2(s, chars, ingoreCase = True):
    if ingoreCase:
    s2 = s.upper().lstri p(chars.upper() )
    return s[len(s)-len(s2):]
    else:
    return s.lstrip(chars)
    What about this:

    def lstrip2(string, chars, ignore_case=Tru e):
    if ignore_case:
    chars = chars.lower() + chars.upper()
    return string.lstrip(c hars)

    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    • Kelie

      #3
      Re: case insensitive lstrip function?

      On Mar 28, 12:55 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
      What about this:
      >
      def lstrip2(string, chars, ignore_case=Tru e):
      if ignore_case:
      chars = chars.lower() + chars.upper()
      return string.lstrip(c hars)
      >
      Ciao,
      Marc 'BlackJack' Rintsch
      Thanks Marc. I think yours looks much better.

      Comment

      Working...