6 4處理剪下板中的字串

2021-08-10 03:35:56 字數 847 閱讀 7521

'''

據一行, 並在前面放置乙個星號。但是假設你有乙個非常大的列表, 希望新增前面

的星號。你可以在每一行開始處輸入這些星號, 一行接一行。或者也可以用一小段

python 指令碼, 將這個任務自動化。

bulletpointadder.py 指令碼將從剪貼簿中取得文字, 在每一行開始處加上星號和空

格, 然後將這段新的文字貼回到剪貼簿。例如, 如果我將下面的文字複製到剪貼簿

lists of animals

lists of aquarium life

lists of biologists by author abbreviation

lists of cultivars

然後執行 bulletpointadder.py 程式, 剪貼簿中就會包含下面的內容:

* lists of animals

* lists of aquarium life

* lists of biologists by author abbreviation

* lists of cultivars

'''import pyperclip

temp=pyperclip.paste()

list=temp.split('\n')

list1=

for item in list:

item1='* '+item

temp='\n'.join(list1) #list1包含修改過的沒一行,但copy需要乙個字串,所以要用join函式連線起來

pyperclip.copy(temp)

主要考察字串join方法的使用

8 1 9 處理字串中的空白

trim 方法能夠從字串的開始位置和末尾移除被指定字元。trimstart 方法能夠從字串的開始位置移除與指定陣列中相同的字元。trimend 方法能夠從字串的結尾移除與指定陣列中相同的字元。trim trimstart 和trimend 方法的過載形式如下 public string trim p...

Python2 處理 Unicode 字串的規則

在 python2 中處理 unicode 字串,需遵循如下規則 1.程式中的字串要加字首 u 2.不要用 str 而應該用 unicode 作為字串轉換函式。不要使用 chr 而應該使用 unichr 3.不要使用 string 模組 4.如非必要,不要使用 encode 和 decode 編譯碼...

對Python2 7處理字串方法的記錄

針對近期學習到的關於python字串與陣列操作的初步知識,進行如下總結 首先,需要明確 字串是不可變的,陣列可任意變化。定義乙個字串 a index 或a index 雙引號與單引號可相互巢狀,並不需要轉義 連線兩個字串 a b或a this is a test 注意被加元素的型別,需要轉型的需加s...