2

ユーザーがテキストを入力できるテキストボックスがあります。現在、次のコードを使用してすべてのスペースと空の行を削除しています:

private void RemoveSpacesAndEmptyLines()
{
    textBox.Lines = textBox.Lines.Where(val => val.Trim().Length != 0).ToArray();
    textBox.Lines = textBox.Lines.Select(c => c.Trim()).ToArray();
}

しかし、1回だけ電話をかけることは可能ですか?
スペース以外の何かを含む行だけを持ち、すべてのスペースを削除する必要があります。

4

3 に答える 3

2
textBox.Lines = textBox.Lines
    .Select(l => l.Trim())
    .Where(l => !string.IsNullOrEmpty(l))
    .ToArray();
于 2013-10-08T14:20:10.123 に答える
-1
function trim (el) {
    el.value = el.value.
       replace (/(^\s*)|(\s*$)/, ""). // removes leading and trailing spaces
       replace (/[ ]{2,}/gi," ").       // replaces multiple spaces with one space 
       replace (/\n +/,"\n");           // Removes spaces after newlines
    return;
}​


onkeypress="return trim(this)"
于 2014-04-14T12:51:40.513 に答える