填充固定长度的字符串 [英] Padding fixed-length strings
问题描述
任何人都可以告诉我一个正则表达式(或函数或其他)
将字符串填充到固定的字节数?
目前我已经将一个var初始化为N个空格,其中N是
最大字符串我必须填充out,然后我将
的子字符串连接到我的源字符串,以便它以正确的大小结束。这一切都运行良好
但是,如果可能的话,我想要一个更通用/更优雅的制造方法
N个空格。是返回{N} * aString的正则表达式吗?
干杯理查德马赫
理查德Maher在2007年4月13日10:35 PM发表以下内容:
任何人都可以告诉我一个正则表达式(或函数或其他)
将一个字符串填充到一个固定的字节数?
目前我有一个var初始化为N个空格,其中''N''是我必须填充的
最大字符串,然后我将
的子字符串连接到我的源字符串这样它的尺寸就合适了。这一切都运行良好
但是,如果可能的话,我想要一个更通用/更优雅的制造方法
N个空格。是返回{N} * aString的正则表达式吗?
var lengthRequired = 12
var testString =" test"
while(testString.length< lengthRequired ){
testString + =" " ;;
}
提醒(">" + testString +"<")
-
兰迪
机会有利于准备好的心灵
comp.lang.javascript常见问题 - http://jibbering.com/faq/index.html
Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/
" Randy Webb" < Hi ************ @ aol.comwrote in message
新闻:4L ****************** ** @ giganews.com ...
Richard Maher在2007年4月13日10:35 PM发表以下内容:
>
任何人都可以告诉我一个正则表达式(或函数或其他),用于将字符串填充为固定的字节数吗? br />
目前我已经将一个var初始化为N个空格,其中N是我必须填充的最大字符串,然后我连接了一个子字符串
到我的源字符串,以便它的大小合适。这一切都很好
但是,如果可能的话,我想要一个更通用/更优雅的方法来制造N个空间。是返回{N} * aString的正则表达式吗?
var lengthRequired = 12
var testString =" test"
while(testString.length< lengthRequired ){
testString + =" " ;;
}
alert(">" + testString +"<")
好吧,嗯,引用你的话,你测试过了吗? :)
-Lost
-Lost说:
>
Randy Webb <嗨************ @ aol.com写了留言
新闻:4L ******************** @ giganews .com ...
> Richard Maher在2007年4月13日10:35 PM发表以下内容:
>>
任何人都可以告诉我一个正则表达式(或函数或其他),用于将字符串填充到固定的字节数?
目前我已经将一个var初始化为N个空格,其中N是我必须填充的最大字符串,然后我连接了一个子字符串
到我的源字符串,以便它的大小合适。这一切都很好
但是,如果可能的话,我想要一个更通用/更优雅的方法来制造N个空间。是返回{N} * aString的正则表达式吗?
var lengthRequired = 12
var testString =" test"
while(testString.length< lengthRequired){
testString + =" " ;;
}
提醒(">" + testString +"<")
嗯,嗯,引用你的话, 你测试过了吗? :)
你呢?它看起来有什么问题?
-
Hi,
Can anyone please show me a regular expression (or function or other) for
padding out a string to a fixed number of bytes?
At the moment I''ve got a var initialized to N spaces, where ''N'' is the
largest string I have to pad out, and then I concatenate a substring of that
to my source string so that it ends up the right size. This all works well
but, if possible, I''d like a more generic/elegant approach to manufacturing
N spaces. Is the a regular expression to returning {N}*aString?
Cheers Richard Maher
Richard Maher said the following on 4/13/2007 10:35 PM:Hi,
Can anyone please show me a regular expression (or function or other) for
padding out a string to a fixed number of bytes?
At the moment I''ve got a var initialized to N spaces, where ''N'' is the
largest string I have to pad out, and then I concatenate a substring of that
to my source string so that it ends up the right size. This all works well
but, if possible, I''d like a more generic/elegant approach to manufacturing
N spaces. Is the a regular expression to returning {N}*aString?var lengthRequired = 12
var testString = "test"
while (testString.length<lengthRequired){
testString += " ";
}
alert(">" + testString + "<")
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
"Randy Webb" <Hi************@aol.comwrote in message
news:4L********************@giganews.com...Richard Maher said the following on 4/13/2007 10:35 PM:>Hi,
Can anyone please show me a regular expression (or function or other) for
padding out a string to a fixed number of bytes?
At the moment I''ve got a var initialized to N spaces, where ''N'' is the
largest string I have to pad out, and then I concatenate a substring of that
to my source string so that it ends up the right size. This all works well
but, if possible, I''d like a more generic/elegant approach to manufacturing
N spaces. Is the a regular expression to returning {N}*aString?
var lengthRequired = 12
var testString = "test"
while (testString.length<lengthRequired){
testString += " ";
}
alert(">" + testString + "<")Well, um, to quote you, "Did you test that?" : )
-Lost
-Lost said:>
"Randy Webb" <Hi************@aol.comwrote in message
news:4L********************@giganews.com...>Richard Maher said the following on 4/13/2007 10:35 PM:>>Hi,
Can anyone please show me a regular expression (or function or other) for
padding out a string to a fixed number of bytes?
At the moment I''ve got a var initialized to N spaces, where ''N'' is the
largest string I have to pad out, and then I concatenate a substring of that
to my source string so that it ends up the right size. This all works well
but, if possible, I''d like a more generic/elegant approach to manufacturing
N spaces. Is the a regular expression to returning {N}*aString?
var lengthRequired = 12
var testString = "test"
while (testString.length<lengthRequired){
testString += " ";
}
alert(">" + testString + "<")
Well, um, to quote you, "Did you test that?" : )Did you? What seems to be wrong with it?
--
这篇关于填充固定长度的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!