How to do String Display Limitation in C#? -


today have learned 2 things

1 - displaying int format : 0001 in text box

number.tostring("0000.");

2 - displaying double format : £ 03.00 in text box

price.tostring("£ 00.00");

my questions is: how display limitation of string in c#?

i mean value in string is

string mystring = "hello world!" 

i display 20 letters display

"hello world!        " 

and if more 20 letters skip displaying rest example:

string mystring = "i love every thing :*" 

it display following:

"i love every thing y" 

20 letters maximum display (counting spaces)..

any idea?

you need use substring or padright

int length = 20; string original = "i love every thing :*";  string finalstring = original.length > length ?                     original.substring(0, length) :                     original.padright(length); 

this take appropriate length substring, or pad spaces, needed.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -