Get multiple numbers from a string

后端 未结 3 1914
轻奢々
轻奢々 2021-01-23 16:40

I have strings like

AS_!SD 2453iur ks@d9304-52kasd

I need to get the 2 frist numbres of the string:

for that case will be:

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-23 17:06

    You can loop chars of your string parsing them, if you got a exception thats a letter if not is a number them you must to have a list to add this two numbers, and a counter to limitate this.

    follow a pseudocode:

    for char in string:
    
    if counter == 2:
     stop loop
    
    if parse gets exception
     continue
    
    else
     loop again in samestring stating this point
     if parse gets exception
      stop loop
     else add char to list
    

提交回复
热议问题