Jump to content

Strip whitespace from a string/Top and tail: Difference between revisions

m
→‎{{header|Phix}}: made p2js compatible, with note
(add bqn)
m (→‎{{header|Phix}}: made p2js compatible, with note)
Line 2,018:
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<lang Phix>(phixonline)-->
<span style="color: #008080;">constantwith</span> <span style="color: #000000008080;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"\ttest\n"javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'\t'</span><span style="color: #0000FF;">&</span><span style="color: #008000;">" test \n"</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">s</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">trim_head</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
Line 2,025 ⟶ 2,026:
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">trim</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
<small>Note that JavaScript deems tab characters as something from the dark ages, especially in strings, and tries valiantly to completely mishandle them in every way it possibly can, for instance the JavaScript statement <code>f("&nbsp;&nbsp;&nbsp;&nbsp;","\t","\x09");</code> <!--(&nbsp; used there for output, but I mean the code as it actually looks)--> leads to f() to receiving three identical parameters of 4 spaces each. The transpiler therefore prohibits tabs in strings but can however fudge a single tab character as 0X9 (ie no quotes) in the JavaScript source code it outputs, and things are fine as long as we forcibly construct any tab-containing strings as per the "&" above, and/or similar subscripting/substitution.</small>
{{out}}
<pre>
"\ttestt test \n"
"testtest \n"
"\ttestt test"
"test"
</pre>
7,813

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.