Whitespace
Các ký tự vô hình như khoảng trắng, tab và xuống dòng. Chúng đóng vai trò quan trọng trong xử lý văn bản và bố cục.
Khoảng trắng chỉ các ký tự vô hình không hiển thị trên màn hình. This includes half-width space (U+0020), tab (U+0009), newline (LF: U+000A, CR: U+000D), full-width space (U+3000), and others. Whitespace plays crucial roles in text formatting, code indentation, data delimiting, and virtually all text processing.
Unicode định nghĩa nhiều loại ký tự khoảng trắng. Ngoài dấu cách nửa độ rộng phổ biến, dấu cách không ngắt (U+00A0) ngăn ngắt dòng và tương ứng với . Full-width space (U+3000) is used for paragraph indentation in Japanese typesetting. Zero-width space (U+200B) has zero display width and serves as a line break hint. Additionally, em space (U+2003), en space (U+2002), thin space (U+2009), and many other typography-specific whitespace characters exist. CSS layout practical guides cover whitespace control methods.
Thuộc tính CSS white-space kiểm soát cách khoảng trắng được hiển thị trong HTML. normal gộp khoảng trắng liên tiếp thành một và cho phép tự động xuống dòng. pre preserves source code whitespace as-is. nowrap suppresses line breaks. pre-wrap preserves whitespace while also allowing auto-wrapping, suitable for code block display.
Xử lý khoảng trắng khác nhau đáng kể giữa các ngôn ngữ lập trình. Python uses whitespace (spaces or tabs) for indentation, and inconsistent indentation causes syntax errors. YAML also uses indentation-based syntax and prohibits tab characters. In JSON, whitespace serves only for readability, and minification (whitespace removal) can significantly reduce file size. The regex \s matches whitespace, but the exact character range varies by language and engine.
Một cạm bẫy phổ biến là trộn lẫn các ký tự khoảng trắng không thể phân biệt bằng mắt. Half-width and full-width spaces, regular spaces and non-breaking spaces look identical but are treated as different characters by programs. Unintended whitespace from copy-paste causing string comparison failures or CSV parsing errors is a frequent real-world issue. Text processing programming books explain precise whitespace handling methods.
Đối với đếm ký tự, có bao gồm khoảng trắng hay không là điểm quyết định quan trọng. Standard character counting includes whitespace, but "character count excluding spaces" is often required. Manuscript fee calculations typically exclude spaces, while social media posts count spaces toward the limit. Character counting tools should display both "with spaces" and "without spaces" counts to serve diverse user needs.