String centering
Suppose I have the following string:
s = "iPhone" ' string length is 6 I want to modify the above string variable such that the string length is 20, AND, the string is centered or padded with spaces. The result should look like: s = " iPhone " ' string length is 20 Does that make sense? I just want to transform a string variable so it is padded with space characters and it appears (somewhat) centered. I prefer a general solution for situations where I want to center the string within a string length of N characters. Thanks! |
String centering
Hi Robert,
Am Tue, 5 Mar 2013 03:00:04 -0700 schrieb Robert Crandal: s = "iPhone" ' string length is 6 I want to modify the above string variable such that the string length is 20, AND, the string is centered or padded with spaces. The result should look like: s = " iPhone " ' string length is 20 center your strings with Home tab = Alignment. If you center your strings with spaces it is hard to find them with MATCH and other functions. If you still want do it, look the REPT function Regards Claus Busch -- Win XP PRof SP2 / Vista Ultimate SP2 Office 2003 SP2 /2007 Ultimate SP2 |
String centering
On Tue, 5 Mar 2013 03:00:04 -0700, "Robert Crandal" wrote:
Suppose I have the following string: s = "iPhone" ' string length is 6 I want to modify the above string variable such that the string length is 20, AND, the string is centered or padded with spaces. The result should look like: s = " iPhone " ' string length is 20 Does that make sense? I just want to transform a string variable so it is padded with space characters and it appears (somewhat) centered. I prefer a general solution for situations where I want to center the string within a string length of N characters. Thanks! Try this: Dim s As String * 20 s = Space((20 - Len(Trim(teststring))) \ 2) & Trim(teststring) & Space(20) |
All times are GMT +1. The time now is 08:45 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com