考虑一个包含数字的字符串,我们需要删除所有不是数字的字符,并用#
替换数字示例1:
A = 234
Output: ###
Ex 2:
A = a2b3c4
Output: ###
示例3:
A = abc
Output: (empty string)
Ex 4:
A = #2a$#b%c%561#
Output: ####
答案 0 :(得分:0)
尽管有更好的方法可以解决您的问题,但可以使用以下方法:
import string
str = "Input string here"
str_new = []
for i in str:
if i in string.digits: str_new.append("#")
print("".join(str_new))
答案 1 :(得分:0)
您可以尝试以下解决方案:
PushbuttonField button = stamper.AcroFields.GetNewPushbuttonFromField(targetButton);
button.Image = image;
stamper.AcroFields.ReplacePushbuttonField(targetButton, button.Field);
否则,您可以尝试以下解决方案:
string = '#2a$#b%c%561#' # input string
new_string = ''
for i in string:
if i.isdigit(): # Check the character type
new_string += '#' # add # if its a digit else don't do any thing