When the "|" character appears inside of a string containing linear box syntax, SyntaxQ returns False and FrontEnd often fails to display the string correctly. Consider:
A string with an alphabetical character embedded in linear box syntax, it's OK:
"\!\(\*StyleBox[\"a\"]\)" // SyntaxQTrueWhen we put the
"|"character (which is ASCII!), something goes wrong:"\!\(\*StyleBox[\"|\"]\)" // SyntaxQFalseWell, let us take what Mathematica suggests:
str = ToString[Style["|"], StandardForm]; str // SyntaxQ str // InputFormTrue "\!\(\*StyleBox[\"\\\"|\\\"\", Rule[StripOnInput, False]]\)"
Now it looks OK, but I wish to have additional "|" in the string, so I try:
str <> "|" // SyntaxQ False
Again something goes wrong (but why???), while with the alphabetical characters it's OK:
str <> "a" // SyntaxQ True
StringJoin of str with itself is also OK, but I don't wish to blow up my file having every "|" character wrapped by the linear syntax. The above is just a minimal working example, of course. Actually I'm constructing a string containing both Bold and Plain (the default style) symbols "|".
I'm working with large strings and wish to keep them as small in size as possible and I'm also trying to make the script as efficient as possible, hence I wish to avoid excessive linear syntax inside of the strings where it isn't strictly necessary.
What is the correct way to compose a large string with differently styled "|" characters? The string have to be as small as possible, with default formatting applied to unstyled characters.

Style[|]which is not valid syntax. Your attempt #3 with the|at the end corresponds toStyle["|"]|which is again not valid syntax. Can you just use "\"|\"" instead of "|"? $\endgroup$