| name | text-processing |
| description | Manipulate and transform text. Use for string operations, parsing, formatting, or text cleanup. |
Text Processing
Transform, parse, and manipulate text data.
Quick Start
text = " Hello, World! "
# Basic operations
text.strip() # "Hello, World!"
text.lower() # " hello, world! "
text.replace(",", "") # " Hello World! "
text.split() # ["Hello,", "World!"]
Common Patterns
Split and join
# Split by delimiter
parts = "a,b,c".split(",") # ["a", "b", "c"]
# Join with delimiter
joined = "\n".join(lines)
# Split lines
lines = text.splitlines()
String formatting
name, value = "count", 42
# f-strings
result = f"{name}: {value}"
# Format with padding
formatted = f"{name:>10}: {value:05d}"
Text search
text = "Hello, World!"
text.startswith("Hello") # True
text.endswith("!") # True
"World" in text # True
text.find("World") # 7 (index)
text.count("l") # 3
Case conversion
text = "hello world"
text.capitalize() # "Hello world"
text.title() # "Hello World"
text.upper() # "HELLO WORLD"
text.swapcase() # "HELLO WORLD"
Parse structured text
# Parse key=value pairs
text = "name=John\nage=30\ncity=NYC"
data = dict(line.split("=") for line in text.splitlines())
# Parse CSV-like
rows = [line.split(",") for line in csv_text.splitlines()]
Clean text
# Remove extra whitespace
clean = " ".join(text.split())
# Remove specific characters
clean = text.translate(str.maketrans("", "", "!@#$%"))