length of variable

G

gordon

Hi
I am writing a short app that will collect some information and produce a
text file based on that information.

One of the values that goes into this text box must be max of 8 characters
long - otherwise it should be truncated to 8.

I used a statement based on if the length is > 8 then substring it to 8 but
i couldnt get the code to work.

Could someone please give me an example? The input is in a text box called
tbName.

thanks

Doug
 
P

Pete Davis

Why not post your code that does this and let us tell you what's wrong with
it?

Pete
 
H

Hans Kesting

Hi
I am writing a short app that will collect some information and produce a
text file based on that information.

One of the values that goes into this text box must be max of 8 characters
long - otherwise it should be truncated to 8.

I used a statement based on if the length is > 8 then substring it to 8 but i
couldnt get the code to work.

Could someone please give me an example? The input is in a text box called
tbName.

thanks

Doug

Are you by any chance trying

tbName.Text.Substring(0, 8);

then try this:

tbName.Text = tbName.Text.Substring(0, 8);


(explanation: strings are immutable, the various methods on string
don't modify the existing string but return a new, modified one)

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top