assigning substring to a variable. String.Remove method .
Hi i try assigning a substring to a variable
"strRemarks = ScmSplit(21).Substring(10, 25)"
when debug i have the following errors
"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index and length must refer to a location within the string."
How to assign a substring to a variable or how can i remove the first 10 substring on a variable
Hope anyone would clarify my question
rgds
vincent
this is happening most likely because your string isn't long enough; here, you are asking to take a sub string of length 25 starting at position 10, meaning your string must have length at least 35. Is this true? You can use the .Length property to check.
vincent cheong wrote: |
| Hi i try assigning a substring to a variable "strRemarks = ScmSplit(21).Substring(10, 25)" when debug i have the following errors "An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll Additional information: Index and length must refer to a location within the string." How to assign a substring to a variable or how can i remove the first 10 substring on a variable Hope anyone would clarify my question rgds vincent
|
|
Hi use this idea, the 1st 10 chars are removed only if the string is longer than 9 characters as i use >=10 in an IF.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myString As String = "1234567890ABCDEFGHIJKLM"
' I'm using an IF to avoid an exception.
' Please try this code with less than 10 characters.If myString.Length >= 10 ThenmyString = myString.Remove(0, 10)
ElseMsgBox("The string 'myString' is less than 10 characters!!")
End If'The output from this is>>'The string 'myString' is now ABCDEFGHIJKLMMsgBox("The string 'myString' is now " & myString.ToString)
End Sub
Regards,
S_DS