㈠ 如何使用python去掉指定的字元串

如果字抄符串是固定為襲{string}這種格式的可以:

s = '{}'

print(s[1:-2])

如果不是固定的格式:
s = '{}'

print(s.split('{')[1].split('}')[0])

㈡ python如何刪除字元串中指定位置的字元

#!/bin/env pythonimport shutil, sys, osdarray = ["Entering directory","In function ","Leaving directory","__NR_SYSCALL_BASE","arm-hisiv100-linux-ar ","arm-hisiv100-linux-gcc ","but argument is of type","dereferencing type-punned pointer will break strict-aliasing rules","differ in signedness","does break strict-aliasing rules","embedded '\0' in format","excess elements in array initializer","implicit declaration of","make -C "," rm -f","this is the location of the previous definition","warning: multi-line comment"]def isInArray (array, line):for item in array:if item in line:return Truereturn Falseif __name__ == '__main__':argv = sys.argvargc = len(argv)if argc < 2:print "Usage: %s <file>" %(os.path.basename(argv[0]))exit()fname = argv[1]fresult = fname + ".result"with open(fname, 'r') as f:with open(fresult, 'w') as g:for line in f.readlines():if not isInArray(darray, line):g.write(line)

㈢ python中刪除字元串中某個字元

刪除字元串中某個字元的時候,可以直接點擊刪除按鈕,或者是理理解按鍵。

㈣ python刪除字元串中指定位置字元

字元串的話,你可以把他當作列表處理:

str = 'hello world'

如果是想去掉第一個字母'o',並且知道是第5個字元, index=4

1.使用分片 new_str = str[:4]+str[5:] ;

2.循環讀取new_str = ''.join([str[i] for i in range(len(str)) if i!= 4]) ;

3.字元替換new_str = str.replace('o','',1) #後面的1代表替換第一個匹配'o'的字元 。

㈤ 急急急,python刪除指定匹配字元串的行!

樓上的是理解錯了吧,我的理解覺得是樓主認為在一行內出現匹配的字元串,而不是整行版和字元串匹配。權把if 那一行修改一下 if len(line.strip().split("pattern string")) == 1:

㈥ python中如何使用正則表達式從字元串中刪除特定字元

可以使用 one_str.replace("EventApplyCheckIn:\/\/", "") 把它替換為空就好

㈦ 如何利用python在一個txt文件中刪除指定的字元

使用replace方法將指定字元串替換為""

㈧ python中如何刪除指定位置前的字元 比如 21-2 刪除-前面的所有字元

關於您的問題,我想到三種思路
s = "21-2"

# 方法一(通用)
# 找到『-』的索引值,然後專加一取出屬減號後面的值
index = s.find('-')+1
print(s[index:])

# 方法二(手工計算便宜)
# 數偏移量
print(s[3:])

# 方法三(取巧,利用-分隔)
# 已『-』為分隔符,取後面的內容
print(s.split('-')[1])