Problem with "right" string function

I have to be missing something obvious but I just can’t see it. The following code reads an XMP document from an Adobe Lightroom Catalog and finds a particular tag and extracts the value - which is an image title. (I start with i = 193 because the first line I’m looking for is 196) Running debugger shows everything working just as expected. It finds the tag, skips to the line with the value, j has a value of 29 which is the occurrence of the >, sTemp is " <rdf:li xml:lang=“x-default”>Firehole Falls, Yellowstone National Park</rdf:li>"

BUT sTitle ends up “wstone National Park</rdf:li>”

Can anyone explain? THANK YOU

		dim i                      As Integer
		dim j                      As Integer
		dim sLineArray()  As String
		dim sTemp           As String
		dim sTitle             As String
		sLineArray = Split(sXMP, EndOfLine)
		i = 193
		while sLineArray(i) <> "<dc:title>"
				sTemp = trim(sLineArray(i))
				j = InStr(sTemp, "<dc:title>")
				if j > 0 then exit
				i = i + 1
		i = i + 2  //skip to the actual title value
		sTemp = trim(sLineArray(i))
		j    = InStr(sTemp, ">")
		sTitle = Right(sTemp, j)

these are the actual lines from the xmp document:

     <rdf:li xml:lang="x-default">Firehole Falls, Yellowstone National Park</rdf:li>

are you compensating for the correct size of the endofline character???
LF=1 CR=1, but CRLF=2

Don’t pass j alone, subtract it from the total length:

sTitle = Right(sTemp, sTemp.Len - j)

Andrew is correct. Right returns the rightmost characters, the number of which are the parameter you passed in. So, in your case, j points to the 29th character, which is where you want it to start. But Right sees that as the number of characters to return. You don’t want the rightmost 29 characters, you want the rightmost characters starting at the 29th character from the left. This is why I generally use Mid since you tell it where to start and, if no length is given, it returns the rest of the string.

Andrew & Dale had the correct answer. Thanks you guys…