跳至正文

新增/移除行號

為文字新增或移除行號的免費線上工具。

Use Cases

  • Code snippets and examples
  • Documentation and tutorials
  • Ordered lists and instructions
  • Log files and debugging
  • Text file analysis

Separator Examples

Dot (.):
1. First line
2. Second line
3. Third line
Parenthesis ():
1) First line
2) Second line
3) Third line
Pipe (|):
1| First line
2| Second line
3| Third line

主要功能

  • 新增/移除模式: 新增或移除行號
  • 設定起始編號: 從您想要的編號開始
  • 選擇分隔符號: 6 種分隔符號樣式
  • 對齊選項: 使用填充進行整齊對齊
  • 自動偵測: 在移除模式中自動識別編號模式
  • 即時複製: 一鍵複製結果

分隔符號樣式

1. 點號 (Dot)

1. First line
2. Second line
3. Third line

用途: 一般列表、文件

2. 括號 (Parenthesis)

1) First line
2) Second line
3) Third line

用途: 有序列表、逐步指南

3. 冒號 (Colon)

1: First line
2: Second line
3: Third line

用途: 日誌檔案、資料分析

4. 垂直線 (Pipe)

1| First line
2| Second line
3| Third line

用途: 程式碼範例、終端機輸出

5. 方括號 (Bracket)

1] First line
2] Second line
3] Third line

用途: 技術文件、參考

6. 大括號 (Brace)

1} First line
2} Second line
3} Third line

用途: 特殊格式、獨特樣式

對齊選項

無填充

1. Line one
2. Line two
...
98. Line ninety-eight
99. Line ninety-nine
100. Line one hundred

套用填充

  1. Line one
2. Line two
...
98. Line ninety-eight
99. Line ninety-nine
100. Line one hundred

使用填充可讓所有編號對齊至相同寬度。

使用案例

1. 程式碼片段

1. def fibonacci(n):
2. if n <= 1:
3. return n
4. return fibonacci(n-1) + fibonacci(n-2)

2. 文件撰寫

1. 簡介
2. 安裝方法
3. 使用方法
4. 疑難排解
5. 參考資料

3. 日誌檔案分析

1: [2024-01-15 10:30:00] INFO: Server started
2: [2024-01-15 10:30:05] INFO: Connection established
3: [2024-01-15 10:30:10] ERROR: Timeout occurred
4: [2024-01-15 10:30:15] INFO: Retry attempt 1

4. 歌詞或詩詞

1| 第一行
2| 第二行
3| 第三行
4| 第四行

5. 食譜步驟

1) 準備食材
2) 預熱平底鍋
3) 加入食材翻炒
4) 烹調 5 分鐘
5) 盛盤上桌

程式設計範例

JavaScript

// 新增行號
function addLineNumbers(text, start = 1, separator = '.') {
const lines = text.split('\n');
const maxDigits = String(start + lines.length - 1).length;

return lines.map((line, index) => {
const lineNumber = start + index;
const padded = String(lineNumber).padStart(maxDigits, ' ');
return `${padded}${separator} ${line}`;
}).join('\n');
}

// 移除行號
function removeLineNumbers(text) {
const lines = text.split('\n');
return lines.map(line => {
return line.replace(/^\s*\d+[.:)|\]}\s]\s*/, '');
}).join('\n');
}

// 使用範例
const text = "Hello\nWorld\nTest";
const numbered = addLineNumbers(text, 1, '.');
console.log(numbered);
/*
1. Hello
2. World
3. Test
*/

const removed = removeLineNumbers(numbered);
console.log(removed);
/*
Hello
World
Test
*/

Python

def add_line_numbers(text, start=1, separator='.', padding=True):
lines = text.split('\n')
max_digits = len(str(start + len(lines) - 1))

result = []
for i, line in enumerate(lines):
line_number = start + i
if padding:
padded = str(line_number).rjust(max_digits)
else:
padded = str(line_number)
result.append(f"{padded}{separator} {line}")

return '\n'.join(result)

def remove_line_numbers(text):
import re
lines = text.split('\n')
return '\n'.join([
re.sub(r'^\s*\d+[.:)|\]}\s]\s*', '', line)
for line in lines
])

# 使用範例
text = "Hello\nWorld\nTest"
numbered = add_line_numbers(text, 1, '.', True)
print(numbered)

💬 這個工具對您有幫助嗎?

如果您覺得這個行號工具實用,歡迎分享給需要的朋友!無論是程式碼檢視、文件編輯或日誌分析,這個工具都能讓您的工作更有效率。

隱私保護

此工具完全在瀏覽器本地端運行。您輸入的所有文字資料都不會傳送到伺服器,僅在您的瀏覽器中處理,確保您的資料安全。

相關工具