Vb 6 listview substring_index

2019-07-25 08:08发布

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条回答
该账号已被封号
2楼-- · 2019-07-25 08:23

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
查看更多
登录 后发表回答