Vb 6 listview substring_index

谁说胖子不能爱 提交于 2019-12-24 11:31:17

问题


I have a listview in vb6 containing the column ID, the values of ID are PID-id where id is equal to id in my database. Ex. PID-56, PID-57. What i want is when i get the value of column id, first value in my listview , let's say PID-56, I only want the ID part which is equal to 56.

Ex.

 value=.text --> PID-56
 newvalue=56 --> PID- is not included so 56 now can be a integer.

How can i remove the 'PID-' considering I am using LIstview in vb6.

What function shoul i be using?


回答1:


If you know that the string always starts with PID- and that format won't ever change, then you can use one of the Basic string manipulation functions. In this case, you probably want to pair the Right function with the Len function. The Len function will return the length of the string (the total number of characters that it contains), and the Right function will return the substring of the specified length, starting from the right side of the whole string.

Finally, you'll need to use one of the standard value conversions to convert that string value into a numeric value. In this case, naturally, you want the CInt operator.

For example:

Private Function ExtractIDFromString(ByRef str As String) As Integer
    Const prefixLength As Long = 4  ' length of the "PID-" prefix

    Dim strID As String
    strID = Right$(str, Len(str) - prefixLength)

    Return CInt(strID)
End Function


来源:https://stackoverflow.com/questions/15401434/vb-6-listview-substring-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!