/ Published in: ASP
URL: http://reusablecode.blogspot.com/2008/09/strpad.html
Pad a string to a certain length with another string. This has probably been the most reused function out of all I've ever written.
Expand |
Embed | Plain Text
<% ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. Const STR_PAD_LEFT = "LEFT" Const STR_PAD_RIGHT = "RIGHT" Const STR_PAD_BOTH = "BOTH" ' Pad a string to a certain length with another string. function str_pad(input, pad_length, pad_string, pad_type) dim output dim difference output = "" difference = pad_length - len(input) if difference > 0 then select case ucase(pad_type) case "LEFT" for i = 1 to difference step len(pad_string) output = output & pad_string next output = right(output & input, pad_length) case "BOTH" output = input for i = 1 to difference step len(pad_string) * 2 output = pad_string & output & pad_string next ' Not sure if it will step far enough when difference is an odd number, so this next block is just in case. if len(output) < pad_length then output = output & pad_string end if output = left(output, pad_length) case else for i = 1 to difference step len(pad_string) output = output & pad_string next output = left(input & output, pad_length) end select else output = input end if str_pad = output end function %>
You need to login to post a comment.
