LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Fixed length padded string

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed length string of text MWysack Excel Discussion (Misc queries) 7 March 21st 13 12:05 AM
Public fixed length string variable Ken Excel Programming 2 February 2nd 09 10:23 PM
creating numbers to a fixed length string... ds Excel Worksheet Functions 4 July 5th 07 01:06 AM
fixed string length,even other record is copied viv Excel Discussion (Misc queries) 0 May 30th 05 08:28 PM
Sorted Fixed Length String Paul Black[_2_] Excel Programming 8 May 19th 05 04:47 PM


All times are GMT +1. The time now is 02:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"