hi all,
Got a little question about Substring (yes, its a .net 2.0 application i'm using it in)
if you use the following code on MyString that is less then 30 characters long, i get an error: (ArgumentOutOfRangeException)
I got 2 solutions:
Solution 1:
Solution 2:
What is the best solution?
Or is there a method that can take everything if it is less then 30 and only the 30 first chars if it is longer than 30 chars?
Got a little question about Substring (yes, its a .net 2.0 application i'm using it in)
if you use the following code on MyString that is less then 30 characters long, i get an error: (ArgumentOutOfRangeException)
Visual Basic:
MyString.Substring(0, 30)
Solution 1:
Visual Basic:
If MyString.Length < 30 Then
Myfield = MyString
Else
Myfield = MyString.SubString(0,30)
End If
Visual Basic:
MyField = MyString.PadRight(30).Substring(0, 30)
What is the best solution?
Or is there a method that can take everything if it is less then 30 and only the 30 first chars if it is longer than 30 chars?
Last edited: