I\'m trying to do a XML request through excel vba for one of the internal links (in our company). when i send request and receive response using the code below, i get the follow
You could use InStrRev
Mid$(responseText, InStrRev(responseText, ":") + 2, (InStrRev(responseText, "}") - 1) - (InStrRev(responseText, ":") + 2))
InStrRev walks the string from right to left. We know you want the value at the end of the string so this direction is useful. We specify as an argument the character to find. The overall string is the responseText
.
The first character to find is ":"
, from right to left. This will be where you have :"13449"}]
. Offset from this + 2 to get the actual start of the value you want, in this case the 1
in 13449
.
Same logic to determine end point of string. I use "}"
as end point then make an adjustment to move forward to the numbers. Mid allows you to specify a string, start point and number of characters. I pass the arguments to extract the required string to Mid
. I used typed functions (with the $
at the end) as more efficient when working with strings.