StringInsert

StringInsert["string","snew",n]

yields a string with "snew" inserted starting at position n in "string".

StringInsert["string","snew",-n]

inserts at position n from the end of "string".

StringInsert["string","snew",{n1,n2,}]

inserts a copy of "snew" at each of the positions n_(i).

StringInsert[{s1,s2,},"snew",n]

gives the list of results for each of the s_(i).

Details

  • StringInsert["string","snew",n] makes the first character of snew the n^(th) character in the new string.
  • StringInsert["string","snew",-n] makes the last character of snew the n^(th) character from the end of the new string.
  • In StringInsert["string","snew",{n1,n2,}] the ni are taken to refer to positions in "string" before any insertion is done. »
  • StringInsert[BioSequence["type","seq"],] will apply the operation to the string "seq", yielding a BioSequence result.

Examples

open allclose all

Basic Examples  (1)

Insert "XYZ" at character position 4:

Scope  (3)

Insert "XYZ" starting 4 character positions from the end of the string:

Insert "XYZ" at several positions:

Insert into a biomolecular sequence:

Applications  (1)

Insert a dot at every third character position:

Count from the end:

Properties & Relations  (2)

Insertion positions always refer to the original string:

Insert "XYZ" to start one character position after the end of the existing string:

An equivalent form:

Possible Issues  (2)

The positions refer to the original string, not the final one:

StringInsert operates on the raw characters in a string:

Wolfram Research (1991), StringInsert, Wolfram Language function, https://reference.wolfram.com/language/ref/StringInsert.html (updated 2020).

Text

Wolfram Research (1991), StringInsert, Wolfram Language function, https://reference.wolfram.com/language/ref/StringInsert.html (updated 2020).

CMS

Wolfram Language. 1991. "StringInsert." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/StringInsert.html.

APA

Wolfram Language. (1991). StringInsert. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringInsert.html

BibTeX

@misc{reference.wolfram_2023_stringinsert, author="Wolfram Research", title="{StringInsert}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/StringInsert.html}", note=[Accessed: 18-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_stringinsert, organization={Wolfram Research}, title={StringInsert}, year={2020}, url={https://reference.wolfram.com/language/ref/StringInsert.html}, note=[Accessed: 18-March-2024 ]}