Jump to content

Compare length of two strings: Difference between revisions

Add V, vlang
(Add V, vlang)
Line 732:
done...
</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}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.