Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have list of strings with varaible lenght in rich text box
for ex.: 01001001
100101110011
100111101011
00110...


i want to copy these strings to another text box by making fixed lenght.

if string length is less pad zeros to msb and limit string lenght to 10

if string length is more than 10 omit msb bits and limit string length to 10

finally i want the output as
0001001001
0101110011
0111101011
....


Thanks in advance

What I have tried:

Dim binString2 As String = (binString1.PadLeft(10, "0"c))


the above coding is padding zeros to left and making string length to 10 if string size is less than 10.
but same is not working if string lentgh is more than 10

it is dispalying as it is without limiting string length

for ex.:

if string is
01001001

it is outputing as 0001001001

but if string is
100101110011

it is outputing as 100101110011 same without limiting string length to 10.
i want it as 0101110011 (msb two bits should be removed)
Posted
Updated 21-May-21 4:11am

You first need to get the length of the string. If it is less than 10 then prepend the appropriate number of zeros. If it is greater than 10 then replace it with a substring of the 10 characters that you wish to display.
 
Share this answer
 
v2
To add to what Richard says, see the String.PadLeft Method (System) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900