返回列表 上一主題 發帖

尋找特定字元,並將之後的字元改為大寫

回復 1# txiec
  1.     Sub nn()
  2. fs = "ucase.txt" '文字檔位置
  3. fd = "temp.txt" '暫存檔預設目錄我的文件
  4. Open fs For Input As #1
  5. Open fd For Output As #2
  6. Do While Not EOF(1)
  7.     Line Input #1, TextLine
  8.     Print #2, UCase(TextLine)
  9. Loop
  10. Close #1
  11. Close #2
  12. Open fd For Input As #1
  13. Open fs For Output As #2
  14. Do While Not EOF(1)
  15. Line Input #1, TextLine
  16.     Print #2, UCase(TextLine)
  17. Loop
  18. Close #1
  19. Kill fd
  20. Close #2
  21. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 4# txiec
  1. Sub nn()
  2. fs = Dir("D:\A\*.txt") 'TXT檔案位置
  3. Do Until fs = ""
  4. fd = "temp.txt" '暫存檔預設目錄我的文件
  5. Open fs For Input As #1
  6. Open fd For Output As #2
  7. Do While Not EOF(1)
  8.     Line Input #1, TextLine
  9.     Print #2, UCase(TextLine)
  10. Loop
  11. Close #1
  12. Close #2
  13. Open fd For Input As #1
  14. Open fs For Output As #2
  15. Do While Not EOF(1)
  16. Line Input #1, TextLine
  17.     Print #2, UCase(TextLine)
  18. Loop
  19. Close #1
  20. Kill fd
  21. Close #2
  22. fs = Dir
  23. Loop
  24. End Sub
複製代碼
學海無涯_不恥下問

TOP

字串中搜尋特定字元位置可使用instr找到位置
用mid獲得與轉寫的字串
再使用Ucase轉成大寫
最後使用replace取代
學海無涯_不恥下問

TOP

本帖最後由 Hsieh 於 2011-2-14 10:22 編輯

回復 13# txiec
  1. Sub nn()
  2. mystr = "姓名: a,b,C,D " '原字串
  3. replacestr = "姓名: " '搜尋字串(不轉大寫)
  4. k = InStr(mystr, replacestr) + Len(replacestr)
  5. temp = Mid(mystr, k) '欲轉成大寫字串
  6. MsgBox Replace(mystr, temp, UCase(temp))
  7. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 15# txiec


    這種問題必需考慮所有文字檔的規則
學海無涯_不恥下問

TOP

回復 17# txiec


    給的方法你自己都不試嗎?
學海無涯_不恥下問

TOP

回復 20# txiec
上傳你的文字檔作說明
學海無涯_不恥下問

TOP

回復 22# txiec
  1. Sub Ex()
  2. fd = ThisWorkbook.Path & "\" '文字檔目錄
  3. fs = Dir(fd & "*.txt") '目錄中的文字檔名
  4. Do Until fs = ""
  5. Open fd & "temp.txt" For Output As #2 '準備暫存檔
  6.   Open fd & fs For Input As #1 '開啟要轉為大寫的文字檔作輸入用
  7.   Do While Not EOF(1)
  8.    Line Input #1, mystr
  9.    If mystr Like "M/C(*),*" Then '如果該字串類似此樣式
  10.    restr = Mid(mystr, InStr(mystr, "),")) '取得要轉為大寫的部份字串
  11.    mystr = Replace(mystr, restr, UCase(restr)) '將原變數
  12.    End If
  13.    Print #2, mystr '將已經轉成大寫的字串寫入暫存檔
  14. Loop
  15. Close #1
  16. Close #2
  17. Open fd & fs For Output As #2 '打開需轉寫的文字檔準備寫入
  18.   Open fd & "temp.txt" For Input As #1 '開啟已轉成大寫的暫存檔
  19.   Do While Not EOF(1)
  20.   Line Input #1, mystr '讀出暫存檔資料
  21.   Print #2, mystr '將暫存檔字串寫入需修改檔案
  22.   Loop
  23. Close #1
  24. Close #2
  25. Kill fd & "temp.txt" '刪除暫存檔
  26. Loop
  27. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 一個人不怕錯,就怕不改過,改過並不難。
返回列表 上一主題