开发者

I need to create a horizontal list from a vertical list of 500 words for a function

I'm creating a 'bad words'开发者_Python百科 filter as str_ireplace function and I have a list of about 500 bad words.. all in a long vertical list. Any idea how I could quickly and easily create a horizontal, comma-delimited formatted list without manually typing a comma after every word and backspacing?

And yes.. I could probably do this in 20 minutes, but I've had this problem before so I'm asking for all the future times I run into this too.


I'd just use find and replace. If whatever editor you're using for your coding can't cope with finding carriage returns try Word, Notepad++, etc.


In php it would be something like:

str_replace(array("\r", "\r\n", "\n"), ", ", $string);

Or

$file = file("list.txt");
print_r($file);

Or, if you want to use bash for that, this would be the thing:

sed -e :a -e '$!N;s/\n/, /;ta' list.txt


file_put_contents('filename', implode(',', file('filename', FILE_IGNORE_NEW_LINES)));

This code rewrite your file exactly as you want

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜