iT邦幫忙

0

VB 文字內的數字+1

  • 分享至 

  • xImage

請問版上的各位大大

目前在寫一段腦子突然轉不過來

如何讓字串IAT08052 往下遞增

想知道各位的邏輯是什麼目前使用 Visual studio VB windows From

例:

IAT08052
IAT08053
IAT08054
IAT08055

race iT邦新手 5 級 ‧ 2020-11-12 21:05:22 檢舉
可用陣列來作
arr=["IAT0805" & row(1:9)]
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
1
海綿寶寶
iT邦大神 1 級 ‧ 2020-11-12 15:10:32
最佳解答

https://ithelp.ithome.com.tw/upload/images/20201112/20001787Ta8pHeY3Lb.png
切開、轉數字、加一、接回去

Module VBModule
    Sub Main()
        dim i as Integer
        dim s as string = "IAT08052"
        Console.WriteLine(s)
        for i = 1 to 10
            s = left(s, 4) & Convert.toInt32(right(s,4))+1
            Console.WriteLine(s)
        next i
    End Sub
End Module
0
ccutmis
iT邦高手 2 級 ‧ 2020-11-12 15:10:51

好久沒用VB了...土法鍊鋼提供您參考

Function PadDigits(val, digits,preset)
  PadDigits = preset & Right(String(digits,"0") & val, digits)
End Function

For i = 8052 To 8055
  wsh.echo PadDigits(i, 5,"IAT")
Next
0
rogeryao
iT邦超人 8 級 ‧ 2020-11-12 15:22:59
public class compiler
  shared function Main as integer
  Dim testString As String = "IAT08052"
  Dim subString As String 
  Dim i As Integer
  for i = 1 to 3
  subString = Left(testString, 3) & Right(Str$(100000+i+Val(Right(testString, 5))),5)   
  Console.WriteLine (subString)
  next i
    return 0
  End function
end class

Demo

2
japhenchen
iT邦超人 1 級 ‧ 2020-11-12 15:32:17

https://dotnetfiddle.net/AlTGgH

dim newid as string
for i = 0 to 1000
    newid = "IAT" &  (8052+i).ToString().PadLeft(5,"0")
			
    console.WriteLine(newid)
next i

輸出

IAT08052
IAT08053
IAT08054
.......
IAT00052

ps: 補齊5位數

0
賽門
iT邦超人 1 級 ‧ 2020-11-13 16:29:24

我比較想回答的問題是: 為什麼我比較喜歡海綿寶寶的寫法?
/images/emoticon/emoticon39.gif

天氣如何?台北今天/images/emoticon/emoticon68.gif

賽門 iT邦超人 1 級 ‧ 2020-11-14 09:44:39 檢舉

南京晴天

我要發表回答

立即登入回答