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

[785 byte] By [vincentcheong] at [2007-12-30]
# 1
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.
TimothyNgMSFT at 2007-9-5 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Hi Timothy,

I manage to use the .length property to assign to a variable and then remove the required substring

rgds

vincent

vincentcheong at 2007-9-5 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
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 Then

myString = myString.Remove(0, 10)

Else

MsgBox("The string 'myString' is less than 10 characters!!")

End If

'The output from this is>>

'The string 'myString' is now ABCDEFGHIJKLM

MsgBox("The string 'myString' is now " & myString.ToString)

End Sub

Regards,

S_DS

Spidermans_DarkSide at 2007-9-5 > top of Msdn Tech,Visual Basic,Visual Basic Language...