Wolfram: Delete SubString
Delete Substring, by Index
StringDrop
-
StringDrop[ str, n]
→ delete first n chars.StringDrop[ str, -n]
→ delete last n chars.StringDrop[ str, {n}]
→ delete nth char.StringDrop[ str, {n, m}]
→ delete nth to mth.StringDrop[ strList, spec ]
→ work on multiple strings.
(* drop first 3 *) StringDrop[ "abcdefg", 3 ] (* defg *) (* last 3 *) StringDrop[ "abcdefg", -3 ] (* abcd *) (* drop 1 char *) StringDrop[ "abcdefg", {3} ] (* abdefg *) (* 3 to 5 *) StringDrop[ "abcdefg", {3,5} ] (* abfg *) (* do on multiple strings *) StringDrop[ {"abc", "def"}, 2 ] (* {c, f} *)
Trim String
StringTrim
-
StringTrim[ str ]
→ delete whitespace at beginning and end.StringTrim[ str, pattern ]
→ delete pattern at beginning and end.
(* trim whitespace *) StringTrim[ " abc\n \n" ] (* abc *) (* trim x *) StringTrim[ "xAxx", "x" ] (* Ax *) (* trim one or more x *) StringTrim[ "xAxx", RegularExpression["x+"] ] (* A *) StringTrim[ "XAXX", RegularExpression["x+"] , IgnoreCase -> True ] (* A *)
Delete Substrings by Pattern
StringDelete
-
Delete parts by Regular Expression .
StringDelete[ "some thing", "thing" ] (* some *) StringDelete[ "some thing", RegularExpression[ "[aeiou]" ] ] (* sm thng *)
WolframLang String
- Wolfram: String
- Wolfram: String Functions
- Wolfram: Get SubString, by Index
- Wolfram: Get SubString, by Pattern
- Wolfram: Delete SubString
- Wolfram: String Split
- Wolfram: String Join
- Wolfram: String Insert
- Wolfram: Convert String
- Wolfram: String Template (format)
- Wolfram: String Match
- Wolfram: String Replace
- Wolfram: Regular Expression
- Wolfram: String Expression
- Wolfram: StringExpression Pattern Syntax
- Wolfram: RegularExpression vs StringExpression