看板 Visual_Basic 關於我們 聯絡資訊
寫了一小段程式,目的為使輸入的字串達到一個英文字加五個數字。 例如說我如果輸入R1,他就要按照規則變成R00001,如果輸入D112, 就要變成D00112。如果輸入W1234,則變成W01234,如果是D12345則 維持不變。 以下是我的寫法(我輸入的位置在Listbox裡): If Len(List1.List(i)) < 6 Then For k = Len(List1.List(i)) To 5 int1 = Left(List1.List(i), 1) intr = Len(List1.List(i)) - 1 List1.List(i) = int1 + "0" + Right(List1.List(i), intr) Next k End If 想請益有沒有更好的方式呢?總覺得我的方法好像笨笨的。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.169.192.201 ※ 編輯: sdwufei 來自: 118.169.192.201 (06/23 15:46)
ClubT:假設輸入的東西存在str變數 06/23 16:49
ClubT:str = Left(str, 1) + Format(Mid(str, 2), "00000") 06/23 16:49
ClubT:把結果傳回str 06/23 16:50
sdwufei:感謝,沒注意到這個指令,真方便XD 06/23 17:39