1樓:匿名使用者
# -*- coding: utf-8 -*-
import re
__author__ = 'lpe234'
raw_str = '****'
def filter_star(_raw_str):
begin_len = len(re.findall(r'(^\**?)[a-za-z]', _raw_str)[0]) if re.
findall(r'(^\**?)[a-za-z]', _raw_str) else 0
end_len = len(re.findall(r'[a-za-z](\**?)$', _raw_str)[0]) if re.
findall(r'[a-za-z](\**?)$', _raw_str) else 0
if begin_len == 0 and end_len != 0:
tmp_str = (raw_str[: -end_len]).replace("*", "")
elif begin_len == 0 and end_len == 0:
tmp_str = (raw_str[:]).replace("*", "")
elif begin_len != 0 and end_len == 0:
tmp_str = (raw_str[begin_len:]).replace("*", "")
else:
tmp_str = (raw_str[begin_len: -end_len]).replace("*", "")
print "*"*begin_len + tmp_str + "*"*end_len
def main():
filter_star(raw_str)
if __name__ == '__main__':
main()
坐等跪謝
C語言 輸入字串,程式設計統計其中的字母 數字 空格 含製表符 標點符號的個數並輸出
include include int main int argc,char argv printf 該字串的字母個數 d個,數字個數 d個,空格個數 d個,標點個數 d個 n alpha,digit,space,spunct return 0 include include int main in...
輸入若干字串,按字串長度由小到大重新排序輸出 使用指標陣列處理
輸入五個字串,然後按字串長度從小到大排序,先把源程式複製一下,char string 5 定義了指標陣列。include include include int main for i 0 i 5 i printf nbefore sort n for i 0 i 5 i for i 0 i 5 i ...
C字串中刪除輸入的字母,如何在c 的字串中刪除某個字串
include include void main void delete string char str,char ch str j 0 這個地方也錯了,j 0,相當於把首字元用空格覆蓋 錯了delete string str 這裡是兩個引數 陣列,被刪除的字母 delete string str...