Created
October 28, 2022 06:09
-
-
Save daanta-real/1ea2a5db4fea4becf71875fbf9c12c91 to your computer and use it in GitHub Desktop.
Get Padded String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // String 채우기(padding) | |
| // 사용법: getPaddedStr(원본문자열, 패딩이 포함된 총 길이, 채울 문자열, 채울 방향) | |
| // ex) getPaddedStr("1135j", 10, "#", "left") = "#####1135j" | |
| function getPaddedStr(strOrg, width, to, direction) { | |
| if(!strOrg) return ""; | |
| var strOrg = new String(strOrg), len = strOrg.length; | |
| if(len >= width) return strOrg; | |
| var strPad = new Array(width - len + 1).join(to); | |
| return (direction == "left" | |
| ? strPad + strOrg | |
| : strOrg + strPad | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment