Compare length of two strings: Difference between revisions
Content added Content deleted
(Add V, vlang) |
|||
Line 732: | Line 732: | ||
done... |
done... |
||
</pre> |
</pre> |
||
=={{header|Vlang}}== |
|||
<lang go>// Compare lenth of two strings, in V |
|||
// Tectonics: v run compare-length-of-two-strings.v |
|||
module main |
|||
// starts here |
|||
pub fn main() { |
|||
mut strs := ["abcd","123456789"] |
|||
println("Given: $strs") |
|||
strs.sort_by_len() |
|||
for i := strs.len-1; i >= 0; i-- { |
|||
println("${strs[i]}: with length ${strs[i].len}") |
|||
} |
|||
// more than 2 strings. note = vs :=, := for definition, = for assignment |
|||
strs = ["abcd","123456789","abcdef","1234567"] |
|||
println("\nGiven: $strs") |
|||
strs.sort_by_len() |
|||
for i := strs.len-1; i >= 0; i-- { |
|||
println("${strs[i]}: with length ${strs[i].len}") |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>prompt$ v run compare-length-of-two-strings.v |
|||
Given: ['abcd', '123456789'] |
|||
123456789: with length 9 |
|||
abcd: with length 4 |
|||
Given: ['abcd', '123456789', 'abcdef', '1234567'] |
|||
123456789: with length 9 |
|||
1234567: with length 7 |
|||
abcdef: with length 6 |
|||
abcd: with length 4</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |