having a few issues trying to convert this code snippet to C#
Private Shared Function GetOccInt(ByVal itm As String) As Integer
Dim pos As Integer = InStr(itm, ">")
Dim strTemp As String = Trim(Replace(Right(Trim(itm), itm.Length - pos), "</b>)</a>", String.Empty))
pos = InStr(strTemp, ">")
Return Convert.ToInt32(Trim(Right(strTemp, strTemp.Length - pos)))
End Function
My final attempt which should be right is, but clearly isn't:
private static int GetOccInt(string itm)
{
var pos = itm.IndexOf(">", StringComparison.Ordinal);
var strTemp = itm.Trim().Substring(itm.Length - pos, itm.Length).Replace("</b>)</a>", "");
pos = strTemp.IndexOf(">", StringComparison.Ordinal);
return Convert.ToInt32(strTemp.Trim().Substring(strTemp.Length - pos, strTemp.Length));
}
when debugging, I'm getting an argument out of range error for the substring function, message = Index and length must refer to a location within the string. Parameter name: length
The first time the breakpoint hit, the index was right (12) and the itm.Length said 31 and it appeared to have 31 charachters, but since itm.length is system code not sure how that could generate an error.