Limit the size of string

  • Thread starter Thread starter Sehboo
  • Start date Start date
S

Sehboo

Hi,

Is there any easy way to limit the size of the string?

I have

Private msDescription As String

I want to limit the msDescription to 50 instead of unlimitted.

I wish I could do something like

Private msDescription As String(50)

How to achive this?

Thanks
 
You can use a StringBuilder object instead of a String.
Here's a nice explanation:

Dim x as New StringBuilder(50,50) 'Creates a string builder with 50
characters and a maximum of 50 characters
x.Append("Hello") ' Appends data to x

Telmo Sampaio
 
* (e-mail address removed) (Sehboo) scripsit:
Is there any easy way to limit the size of the string?

I have

Private msDescription As String

I want to limit the msDescription to 50 instead of unlimitted.

I wish I could do something like

Private msDescription As String(50)

How to achive this?

Just FMI: Why? As you are responsible for assigning something to the
string, you can easily check the length before assinging something.
 
Hi Sehboo.

Private myDescription as String
Private msDescription As String

myDescription = msDescription.substring(0,50)

I hope this helps,

Cor
 
Back
Top