K
kellygreer1
What is a good one line method for doing a "length safe"
String.Substring?
The VB classes offer up the old Left function so that
string s = Microsoft.VisualBasic.Left("kelly",200)
// s will = "kelly" with no error
// but
string s2 = "kelly".Substring(0,200)
// results in
// ArgumentOutOfRangeException
// Index and length must refer to a location within the string.
What is the most compact (one-line) method of doing the same thing with
Substring?
Maybe using Substring and Length and some other method...
Maybe I am just missing something.
Strange that the SUBSTRING in T-SQL is "length safe"...
Is the code below the best way of getting the same effect without the
VB Left?
//seems like a hack
string s = "this is some string"
string safeStr = s.PadRight(200).Substring(0,200).Trim()
Thanks in advance,
Kelly Greer
(e-mail address removed)
change nospam to yahoo
String.Substring?
The VB classes offer up the old Left function so that
string s = Microsoft.VisualBasic.Left("kelly",200)
// s will = "kelly" with no error
// but
string s2 = "kelly".Substring(0,200)
// results in
// ArgumentOutOfRangeException
// Index and length must refer to a location within the string.
What is the most compact (one-line) method of doing the same thing with
Substring?
Maybe using Substring and Length and some other method...
Maybe I am just missing something.
Strange that the SUBSTRING in T-SQL is "length safe"...
Is the code below the best way of getting the same effect without the
VB Left?
//seems like a hack
string s = "this is some string"
string safeStr = s.PadRight(200).Substring(0,200).Trim()
Thanks in advance,
Kelly Greer
(e-mail address removed)
change nospam to yahoo