jiga
jiga

Reputation: 133

Removing characters if string is larger than 255 characters

I want to Remove string Characters if string is more than varchar(255) length and save that in database in c#

I am not able to find any solution .

string test.RatingItemName="hshhhdhhdshdsdsddssdsdsghdsh";

if (test.RatingItemName > varchar(255))
{
    //trim the extra characters after varchar(255)
}

Upvotes: 1

Views: 2442

Answers (1)

apomene
apomene

Reputation: 14389

Simply use substring. Try like:

string test.RatingItemName="hshhhdhhdshdsdsddssdsdsghdsh";
if(test.RatingItemName.Length>255)
{
   test = test.RatingItemName.Substring(0,255);
}

Upvotes: 6

Related Questions