I tried the following:
var a = description.Substring(0, 150);
However this gives a problem if the length of description is less than 150 chars. So is there another way I can limit the length to 150 that won't give an error when string length is for example 20.
Make a loop at the end of the string. After cutting the string at the proper length, take the end of the string and tie a knot at the very end, then fold the string over and tie a loop, about the same size as the original loop (about 2cm in diameter).
The ‹ ^ › and ‹ $ › anchors ensure that the regex matches the entire subject string; otherwise, it could match 10 characters within longer text. The ‹ [A-Z] › character class matches any single uppercase character from A to Z, and the interval quantifier ‹ {1,10} › repeats the character class from 1 to 10 times.
While an individual quoted string cannot be longer than 2048 bytes, a string literal of roughly 65535 bytes can be constructed by concatenating strings.
var a = description == null
? string.Empty
: description.Substring(0, Math.Min(150, description.Length));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With