473,320 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to make sure a string is not longer that some given value

I'd like to make sure a string is no longer that some value.

What is the best way to do that.

For example, it would be nice if I could do:

ControlComboBoxName.Text = name.Substring(0, mITEM_NAME_LENGTH)

where if name was shorter that mITEM_NAME_LENGTH it would return name.

Thanks
Nov 21 '05 #1
8 1047
**Developer**,
Instead of using SubString consider using VB.Left.

Something like:

Imports VB = Microsoft.VisualBasic

Dim name As String = "Jay"
Dim mITEM_NAME_LENGTH As Integer = 10
Dim Text As String = VB.Left(name, mITEM_NAME_LENGTH)

The Imports alias ensures that the Microsoft.VisualBasic.Strings.Left
function is called instead of the property Form.Left property.

Hope this helps
Jay

" **Developer**" <RE*************@a-znet.com> wrote in message
news:ep*************@TK2MSFTNGP11.phx.gbl...
| I'd like to make sure a string is no longer that some value.
|
| What is the best way to do that.
|
| For example, it would be nice if I could do:
|
| ControlComboBoxName.Text = name.Substring(0, mITEM_NAME_LENGTH)
|
| where if name was shorter that mITEM_NAME_LENGTH it would return name.
|
|
|
|
|
| Thanks
|
|
Nov 21 '05 #2
I've been avoiding the VB functions. I think what turned me from them is
that Mid is 1-based and all of Net is 0-based.
But I don't see why I shouldn't use Left and Right since they are simpler
then the Net methods.
So that's what I'll do.
Maybe I needed a MVP to tell me it's OK.

Thanks
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
message news:e1**************@TK2MSFTNGP09.phx.gbl...
**Developer**,
Instead of using SubString consider using VB.Left.

Something like:

Imports VB = Microsoft.VisualBasic

Dim name As String = "Jay"
Dim mITEM_NAME_LENGTH As Integer = 10
Dim Text As String = VB.Left(name, mITEM_NAME_LENGTH)

The Imports alias ensures that the Microsoft.VisualBasic.Strings.Left
function is called instead of the property Form.Left property.

Hope this helps
Jay

" **Developer**" <RE*************@a-znet.com> wrote in message
news:ep*************@TK2MSFTNGP11.phx.gbl...
| I'd like to make sure a string is no longer that some value.
|
| What is the best way to do that.
|
| For example, it would be nice if I could do:
|
| ControlComboBoxName.Text = name.Substring(0, mITEM_NAME_LENGTH)
|
| where if name was shorter that mITEM_NAME_LENGTH it would return name.
|
|
|
|
|
| Thanks
|
|

Nov 21 '05 #3
On 2005-09-03, **Developer** <RE*************@a-znet.com> wrote:
I'd like to make sure a string is no longer that some value.

What is the best way to do that.

For example, it would be nice if I could do:

ControlComboBoxName.Text = name.Substring(0, mITEM_NAME_LENGTH)

where if name was shorter that mITEM_NAME_LENGTH it would return name.


ControlComboBoxName.Text = name.Substring(0,
Math.Min(ControlComboBoxName.Text.length, mITEM_NAME_LENGTH))
Nov 21 '05 #4
**Developer**,
Yes! the "one off" problem is usually why I tend to avoid VB.Mid also. Or
should I say I limit its use & try not to mix VB.Strings.* & String.*
methods as you say one is one-based & the other is zero-based, mixing them
can lead to confusion.

Otherwise I try to use the right tool for the right job... In this case
VB.Left feels like a good fit for the right tool, Although as dfoster shows,
its easy enough to write your own...

Hope this helps
Jay
" **Developer**" <RE*************@a-znet.com> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
| I've been avoiding the VB functions. I think what turned me from them is
| that Mid is 1-based and all of Net is 0-based.
| But I don't see why I shouldn't use Left and Right since they are simpler
| then the Net methods.
| So that's what I'll do.
| Maybe I needed a MVP to tell me it's OK.
|
| Thanks
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
| message news:e1**************@TK2MSFTNGP09.phx.gbl...
| > **Developer**,
| > Instead of using SubString consider using VB.Left.
| >
| > Something like:
| >
| > Imports VB = Microsoft.VisualBasic
| >
| > Dim name As String = "Jay"
| > Dim mITEM_NAME_LENGTH As Integer = 10
| > Dim Text As String = VB.Left(name, mITEM_NAME_LENGTH)
| >
| > The Imports alias ensures that the Microsoft.VisualBasic.Strings.Left
| > function is called instead of the property Form.Left property.
| >
| > Hope this helps
| > Jay
| >
| > " **Developer**" <RE*************@a-znet.com> wrote in message
| > news:ep*************@TK2MSFTNGP11.phx.gbl...
| > | I'd like to make sure a string is no longer that some value.
| > |
| > | What is the best way to do that.
| > |
| > | For example, it would be nice if I could do:
| > |
| > | ControlComboBoxName.Text = name.Substring(0, mITEM_NAME_LENGTH)
| > |
| > | where if name was shorter that mITEM_NAME_LENGTH it would return name.
| > |
| > |
| > |
| > |
| > |
| > | Thanks
| > |
| > |
| >
| >
|
|
Nov 21 '05 #5
On 2005-09-03, Jay B. Harlow [MVP - Outlook] <Ja************@tsbradley.net> wrote:
**Developer**,
Yes! the "one off" problem is usually why I tend to avoid VB.Mid also. Or
should I say I limit its use & try not to mix VB.Strings.* & String.*
methods as you say one is one-based & the other is zero-based, mixing them
can lead to confusion.

Otherwise I try to use the right tool for the right job... In this case
VB.Left feels like a good fit for the right tool,


I tend to avoid the VB strings functions, both for the count-from-one
problem and the tendency of them to equate Nothing and String.Empty, but
I must admit that VB.Left has the correct semantics here. String really
needs a TrimLength function or something.
Nov 21 '05 #6
If you are working with userinput to a combo or text box, you can set the
maxlength of both to limit the user's input to a maximum number of characters.

If you are trying to fit text to the width of the text box or combo box, you
should use the create graphics for the control and the measureString method
or even writestring method and stringformat. With either method you can get
a nice "..." at the end of the truncated text showing the user there is more
text other than what's shown.

Just some suggestions.

--
Dennis in Houston
"**Developer**" wrote:
I'd like to make sure a string is no longer that some value.

What is the best way to do that.

For example, it would be nice if I could do:

ControlComboBoxName.Text = name.Substring(0, mITEM_NAME_LENGTH)

where if name was shorter that mITEM_NAME_LENGTH it would return name.

Thanks

Nov 21 '05 #7
Jay, Dennis and dfoster

Thanks
Nov 21 '05 #8
One problem with VB.Left is that QuickWatch does not seem to be able to
display the result!

For example:

VB.Left(name, mITEM_NAME_LENGTH)

'VB.Left' is not declared or the module containing it is not loaded in the
debugging session.
" **Developer**" <RE*************@a-znet.com> wrote in message
news:ep*************@TK2MSFTNGP11.phx.gbl...
I'd like to make sure a string is no longer that some value.

What is the best way to do that.

For example, it would be nice if I could do:

ControlComboBoxName.Text = name.Substring(0, mITEM_NAME_LENGTH)

where if name was shorter that mITEM_NAME_LENGTH it would return name.

Thanks

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Christos TZOTZIOY Georgiou | last post by:
This is a subject that comes up fairly often. Last night, I had the following idea, for which I would like feedback from you. This could be implemented as a function in codecs.py (let's call it...
21
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your...
10
by: Daniel | last post by:
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string?
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
7
by: André | last post by:
Hi, I need several cookies depending of an variable (x), so i defined a HttpCookie() as an array. My problems: 1)I get the error: Object reference not set to an instance of an object. 2)My...
13
by: fool | last post by:
Dear group, I want to check if the given string is a number. If any value is inputed other than a number then error. The following is not the correct solution. Can some one tell me any link for...
2
by: dougloj | last post by:
Hi. I have an ASP.NET application written in C#. To log in, a user must provide their email address and password. I already give the user a "Remember my Email Address" check box. If they check...
82
by: Bill David | last post by:
SUBJECT: How to make this program more efficient? In my program, a thread will check update from server periodically and generate a stl::map for other part of this program to read data from....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.