Results for “Strings & text”
Small, practical examples. Search by task or narrow things down below.
Write a multiline string without expanding variables
PowerShell: A single-quoted here-string preserves dollar signs literally.
PowerShell✓ Tested
Build text incrementally with StringBuilder
C#: Append fragments instead of repeatedly concatenating intermediate strings in a loop.
C#✓ Tested
Check whether text contains a phrase
Use a case-sensitive Java substring check.
Java✓ Tested
Convert ASCII text to uppercase
Convert characters with toupper while avoiding signed-char undefined behavior.
C✓ Tested
Copy text into a fixed buffer
Use snprintf and check for truncation when copying a C string.
C✓ Tested
Extract numbers from text
Find all runs of ASCII digits in a string and convert the matches to integers.
regex✓ Tested
Find text ignoring case
Use ordinal case-insensitive comparison for a C# substring search.
C#✓ Tested
Read rows from CSV text
Parse CSV into objects with named properties.
CSV✓ Tested
Replace literal text
Replace every literal occurrence in a C# string.
C#✓ Tested
Replace literal text
Replace all literal matches in a Java string without regular expressions.
Java✓ Tested
Replace text in a string
Replace every occurrence of a substring and keep the result in a new string. The original string is unchanged.
string✓ Tested
Split and trim text
Split simple comma-separated JavaScript text and trim each part.
JavaScript✓ Tested