String length: Difference between revisions
Content added Content deleted
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
(Add a Brainf*** code example) |
||
Line 755: | Line 755: | ||
. vap$((=.!arg).!arg):? [?length&!length |
. vap$((=.!arg).!arg):? [?length&!length |
||
);</syntaxhighlight> |
);</syntaxhighlight> |
||
=={{header|Brainf***}}== |
|||
===Byte Length== |
|||
There are several limitations Brainf*** has that influence this solution: |
|||
- Brainf*** only supports 8-bit numbers in canonical implementations, so it only supports strings of length below 255. |
|||
- The rule of thumb in Brainf*** when reading a string is to always store exactly one byte, no matter how much bytes a character represents. That's why this solution is a strictly ByteLength one. |
|||
- No way to pass anything to Brainf*** but giving the arguments as input. That's why this program reads a string and outputs the number of bytes in it. |
|||
[[https://esolangs.org/wiki/Brainfuck_algorithms#Print_value_of_cell_x_as_number_for_ANY_sized_cell_.28eg_8bit dot 2C_100000bit_etc.29]] is used to print the number from memory. |
|||
<syntaxhighlight lang="bf"> |
|||
,----- ----- [>,----- -----] ; read a text until a newline |
|||
<[+++++ +++++<] ; restore the original text |
|||
>[[-]<[>+<-]>+>]< ; add one to the accumulator cell for every byte read |
|||
;; from esolang dot org |
|||
>[-]>[-]+>[-]+< [>[-<-<<[->+>+<<]>[-<+>]>>]++++++++++>[-]+>[-]>[-]> [-]<<<<<[->-[>+>>]>[[-<+>]+>+>>]<<<<<]>>-[-<<+>>]<[-]++++++++ [-<++++++>]>>[-<<+>>]<<] <[.[-]<] |
|||
[-]+++++ +++++. ; print newline |
|||
</syntaxhighlight> |
|||
=={{header|C}}== |
=={{header|C}}== |