HELP: Fixed Length String ?
-
Hi all, I have a situation where I need to return a fixed length string regardless of the length of a string that has been assigned to it. For example, if I wanted to have String1 which is made up of 12 spaces, then assing a returned value to a String2 which can be anything from 1 to 12 characters in length, how is this best done ? The following may give you an idea where I'm coming from:
String^ Result; //This needs to be a fixed 12 characters.
String^ s1 = "ABC"; Result = s1;
So I needResult
to return'ABC'
+ 9 spaces. Hope this all makes some sense.... Fritzables. -
Hi all, I have a situation where I need to return a fixed length string regardless of the length of a string that has been assigned to it. For example, if I wanted to have String1 which is made up of 12 spaces, then assing a returned value to a String2 which can be anything from 1 to 12 characters in length, how is this best done ? The following may give you an idea where I'm coming from:
String^ Result; //This needs to be a fixed 12 characters.
String^ s1 = "ABC"; Result = s1;
So I needResult
to return'ABC'
+ 9 spaces. Hope this all makes some sense.... Fritzables.String^ result; String^ s1 = "ABC"; result = (s1->Length > 12 ? s1->Substring(0, 12) : s1)->PadRight(12); Console::WriteLine("[{0}] Length={1}", result, result->Length); "We make a living by what we get, we make a life by what we give." --Winston Churchill
-
String^ result; String^ s1 = "ABC"; result = (s1->Length > 12 ? s1->Substring(0, 12) : s1)->PadRight(12); Console::WriteLine("[{0}] Length={1}", result, result->Length); "We make a living by what we get, we make a life by what we give." --Winston Churchill
George, you're a legend.... works a treat. Thanks a million. Regards Pete