l = ':;\'"[email protected]#$%^&*()_-=+][{}~`.><?/\\|' # list of character that can be used for emoticons
s = '<p>This :) is an example for:) emoticons :)</p>'
我用s.replace(':)', '<img>')
和人物,Python的 - 更換的表情
result = '<p>this <img> is an example for<img> emoticons <img></p>'
如何使結果類似:
result = '<p>this <img> is an example for:) emoticons <img></p>'
感謝您的幫助!
編輯:我有一個初始名單l
。用戶只能使用l
中的字符製作表情符號。例如::)
,:]
,等。對於每個表情符號,我將分別將其更改爲圖像作爲迴應。因此用戶必須正確輸入數據:通配符應該是獨立的。最難的部分是輸入數據包含HTML標籤。
更具體一些。當「」子字符串被空白包圍時,是否只想進行替換?你想「爲:)」變成「爲」? – 2012-08-10 22:05:18
我不知道太多的python,但我認爲你可以這樣做:1)首先搜索第二''並返回這個索引2)你可以分成兩部分s [1-index] s [( index + 4)-length(s)] 3)現在你可以使用replace()。 – 2012-08-10 22:07:42
哦,我的壞。編輯! :) – ben 2012-08-10 22:07:51