1

In VFP there is a common function in most languages. It is: STRTRAN(var1,'abc') This function adjusts the var1 variable by taking out the sub-string "abc".

As an example:

STRTRAN("Hello yee valiant ones!", 'yee ') leads to "Hello valiant ones!"

Does python have anything like that? I only find some RegEx and confounding ways which is rather abstruse to me.

Many thanx for your help

DK

4

2 回答 2

5

您可以使用str.replace

>>> strs = "Hello yee valiant ones!"
>>> strs.replace(' yee','')
'Hello valiant ones!'
#or
>>> strs.replace('yee ','')
'Hello valiant ones!'
于 2013-06-26T09:35:08.313 回答
2

有一种str.translate方法,但它只适用于孤立的字符。你可能想要str.replace

>>> "Hello yee valiant ones!".replace('yee ', '')
'Hello valiant ones!'
于 2013-06-26T09:35:28.540 回答