VB.NET string truncate method. How to truncate a string using substring() method


.NET method for truncating a string. First check to make sure string is long enough and then return a substring of the value and if so then with the specified length --- [maxLength]

 

    Protected Function strTruncate(ByVal value As String, ByVal maxLength As Integer) As String
        If (String.IsNullOrEmpty(value)) Then
            Return value
        Else
            Return value.Substring(0, Math.Min(value.Length, maxLength))
        End If
    End Function

 

use like this:

 

Dim trimCommentary As String = strTruncate(commentaryPane, 512)

Tags: truncate method
Last update:
2014-09-02 21:33
Author:
Mark
Revision:
1.0
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Records in this category

Tags