473,668 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)
Mar 28 '08 #1
2 2115
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
Mar 28 '08 #2
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.
Mar 29 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4428
by: noah | last post by:
Can anyone think of a way to make array keys case insensitive? An option on any recent PHP would be to convert all array keys to lowercase using the standard array_change_key_case() function. As it turns out, I'm stuck on a PHP 4.1.3 system, so that function is not available to me. Can anyone think of an efficient way to write my own version of this function? Can I edit keys in place without copying the values, or will I have to copy the...
8
2862
by: Pete Jereb | last post by:
Python 2.3 (#46, Jul 29 2003, 18:54:32) on win32 >>> s = 'chg bonn_fee' >>> print s chg bonn_fee >>> print s.lstrip('chg ') bonn_fee >>> s = 'chg conn_fee'
4
3330
by: joram gemma | last post by:
Hello, on windows python 2.4.1 I have the following problem >>> s = 'D:\\music\\D\\Daniel Lanois\\For the beauty of Wynona' >>> print s D:\music\D\Daniel Lanois\For the beauty of Wynona >>> t = 'D:\\music\\D\\' >>> print t D:\music\D\
32
3142
by: Elliot Temple | last post by:
Hi I have two questions. Could someone explain to me why Python is case sensitive? I find that annoying. Also, why aren't there multiline comments? Would adding them cause a problem of some sort? Thanks, Elliot
5
18451
by: Madjid Nasiri | last post by:
Hi, I am basic in oracle. My Old programs write with Delphi and Databases: Access, Paradox, MySQL, Microsoft SQL. I write my code (SQL code) case-insensitivae, but now i need use oracle database. The Oracle by default is case-sensitive, How can used case-insensitive in oracle. Thanks Madjid Nasiri
2
10304
by: Tom | last post by:
Hi, Our development team is adding DB2 8.1 compatibility to our existing application which currently supports SQLServer 2000. Our code is written to take advantage of SQLServer's ability to allow query string compares to be case insensitive. We have identified DB2 forces all query string compares to be evaluated case sensitive. Since our code is written to assume case insensitivity, it curently seems that we must change our code...
2
8909
by: Nikhil Ekke | last post by:
Hi, I am parsing an XML file. I am using the function GetElementsByTagName() function. But I want this function to give me the XMLNodeList which is case insensitive. Suppose there r nodes like this <time/> <Time/>
1
5512
by: benhoefer | last post by:
I have been searching around and have not been able to find any info on this. I have a unique situation where I need a case sensitive map: std::map<string, intimap; I need to be able to run a find on this map with a case sensitive AND case insensitive search. I need to be able to change this dynamically during execution. Is this possible? Any thoughts on this? I understand that I can make the map case insensitive, but that is not...
7
3328
by: Adrian | last post by:
Hi, I want a const static std::set of strings which is case insensitive for the values. So I have the following which seems to work but something doesnt seem right about it. Is there a better way or any gotcha's from my code below.
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8889
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8572
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8652
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.