Total string length
-
Hi, I am trying to set the length of a field to a pre-defined certain value. For this reason I am padding right incase it is not the required lenght. for example String1 = "Trailer1" String2 = "Tra" String1.ToString.PadRight(6) = "Traile" - should get me this value String2.ToString.PadRight(6) = "Tra " - should get me this value. Is it correct to use padright to limit the length of string? Thanks so much for your time.
-
Hi, I am trying to set the length of a field to a pre-defined certain value. For this reason I am padding right incase it is not the required lenght. for example String1 = "Trailer1" String2 = "Tra" String1.ToString.PadRight(6) = "Traile" - should get me this value String2.ToString.PadRight(6) = "Tra " - should get me this value. Is it correct to use padright to limit the length of string? Thanks so much for your time.
PadRight will not limit the length it will only pad it. You example is not correct, but if you did: String1.ToString.PadRight(6) = "Traile1" you would still get all seven characters. If you want to get only six characters you will need to substring after the padright String1.ToString.PadRight(6).Substring(0,6) Hope that helps. Ben