By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,238 Members | 1,485 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,238 IT Pros & Developers. It's quick & easy.

Limit the size of string

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You could make a property of type string, then in the accessor verify its
length and either throw an exception or just disallow it.

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/...ity/newsgroups
"Sehboo" <ma*********@hotmail.com> wrote in message
news:7b**************************@posting.google.c om...
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

Nov 20 '05 #2

P: n/a
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

"Sehboo" <ma*********@hotmail.com> wrote in message
news:7b**************************@posting.google.c om...
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

Nov 20 '05 #3

P: n/a
Hi,

<VBFixedString(50)> Dim msDescription As String

Ken

----------------------

"Sehboo" <ma*********@hotmail.com> wrote in message
news:7b**************************@posting.google.c om...
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

Nov 20 '05 #4

P: n/a
* ma*********@hotmail.com (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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

P: n/a
Hi Sehboo.

Private myDescription as String
Private msDescription As String

myDescription = msDescription.substring(0,50)

I hope this helps,

Cor
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.