Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What's the easiest way to modify a string in a variable so that it only holds a maximum of 16 characters, and if it's less than 16 characters I want to attach asterisk "*" characters until it makes the string length 16?
Here are some before-after examples: BEFO s = "french fries" ' Len = 12 AFTER: s = "french fries****" ' Len = 16 BEFO s = "" ' Len = 0 AFTER: s = "****************" ' Len = 16 BEFO s = "tree" ' Len = 4 AFTER: s = "tree************" ' Len = 16 BEFO s = "There are fries." ' Len = 16 AFTER: s = "There are fries." ' Len = 16 The last example has 16 characters, so there's no need to pad it. I think I could do this simply in C/C++ with the printf() format string, but I'm looking for a quick way to do this with VBA. Thanks. -Robert |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Also, if the input string is greater than 16 chars, then truncate it to just 16 characters:
BEFO s = "The quick brown fox jumps over the lazy dog." ' Len = 40 AFTER: s = "The quick brown fox " ' Len = 16 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On 21-Sep-2019 11:19 AM, RG III wrote:
What's the easiest way to modify a string in a variable so that it only holds a maximum of 16 characters, and if it's less than 16 characters I want to attach asterisk "*" characters until it makes the string length 16? Here are some before-after examples: BEFO s = "french fries" ' Len = 12 AFTER: s = "french fries****" ' Len = 16 BEFO s = "" ' Len = 0 AFTER: s = "****************" ' Len = 16 BEFO s = "tree" ' Len = 4 AFTER: s = "tree************" ' Len = 16 BEFO s = "There are fries." ' Len = 16 AFTER: s = "There are fries." ' Len = 16 The last example has 16 characters, so there's no need to pad it. I think I could do this simply in C/C++ with the printf() format string, but I'm looking for a quick way to do this with VBA. Thanks. -Robert How about:- s = left(s & String(16, "*"), 16) |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Friday, September 20, 2019 at 5:40:31 PM UTC-7, malone wrote:
How about:- s = left(s & String(16, "*"), 16) Bravo bravo! That works for me. Thanks! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Fixed length string of text | Excel Discussion (Misc queries) | |||
Public fixed length string variable | Excel Programming | |||
creating numbers to a fixed length string... | Excel Worksheet Functions | |||
fixed string length,even other record is copied | Excel Discussion (Misc queries) | |||
Sorted Fixed Length String | Excel Programming |