I am getting an error after using substring method of c# on this input rbnRating_8
:
Error:System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. Parameter name: length at System.String.Substring(Int32 startIndex, Int32 length)
Below is my substring code:
rbn.ID.Substring(rbn.ID.IndexOf("_", 0) + 1, rbn.ID.Length)
I recently started working with vb.net so I tried same above code in Java and it works fine without any error but same code throws error in vb.net. Is there any logical difference on why it works in one and not in other?
Below is the full code:
Try Dim rbn As RadioButton = CType(sender, RadioButton) Dim ClientId As Integer = 0 If rbn IsNot Nothing AndAlso Integer.TryParse(rbn.ID.Substring(rbn.ID.IndexOf("_", 0) + 1, rbn.ID.Length), ClientId) AndAlso ClientId > 0 Then // .. some code here End If Catch ex As Exception Dim oErr As New ErrLog(ex) Exit Sub End Try
Java code:
public static void main(String[] args) { String abc = "rbnRating_8"; System.out.println(abc.substring(abc.indexOf("_", 0) + 1, abc.length())); }