Click to See Complete Forum and Search --> : Limit the characters returned by a string?


ajn1888
08-11-2005, 06:43 AM
Hi,

Does anyone know how to limit the characters returned by a string?

So, I have a string that will be of variable length, I want to limit the number of characters to 150.

This string is being created dynamically in .NET and therefore cannot be limited at the SQL back end.

Any ideas? :confused:

Thanks.

AJN

A1ien51
08-11-2005, 06:48 AM
Check the string length, if it is greater than your max then use the substring to retrieve only the max length allowed.

Eric

ajn1888
08-11-2005, 06:52 AM
Thanks for that. Hate to sound stupid, but where/how do I set the max length and how do I retrieve the max length allowed?

Thanks again.

AJN

A1ien51
08-11-2005, 06:54 AM
Where is this max length coming from? Sounded like you already knew the max length you wanted.

Eric

ajn1888
08-11-2005, 07:01 AM
Sorry if I'm being vague.

I am unsure of the syntax for this.

I have a string called 'strSearchSummaryLabel' which I want to limit to 150 characters at the most. I would like to hard-code the max limit if possible.

As a further explanation, this string will populate a label called 'lblSearchCriteria'. As the string is dynamically created by the user, I need to limit the length in order to preserve space and the shape of my website.

I know how to limit strings in SQL, but not in .NET unfortunately!

Thanks.

AJN

A1ien51
08-11-2005, 08:32 AM
Somoething like this:

If strValue.length > 150 Then
strValue =- strValue.Substring(0,150)
End If

Eric

ajn1888
08-11-2005, 09:26 AM
Aha! Easy when you know how!

Thank you. :)

AJN