nim


Converting a seq[char] to string


I'm in a situation where I have a seq[char], like so:
import sequtils
var s: seq[char] = toSeq("abc".items)
What's the best way to convert s back into a string (i.e. "abc")? Stringifying with $ seems to give "#[a, b, c]", which is not what I want.
The most efficient way is to write a procedure of your own.
import sequtils
var s = toSeq("abc".items)
proc toString(str: seq[char]): string =
result = newStringOfCap(len(str))
for ch in str:
add(result, ch)
echo toString(s)
import sequtils, strutils
var s: seq[char] = toSeq("abc".items)
echo(s.mapIt(string, $it).join)
Join is only for seq[string], so you'll have to map it to strings first.

Related Links

printing an array in Nim using echo
Nim stored procedure reference in tuple
Remove constant after compilation in Nim
How do I use a `concept` in Nim?
how to create an IntSet on the heap in nim?
How to benchmark few lines of code in nim?
what is nim type definition for generic procedure?
Does a nim library contain an argsort implementation or wrapper?
nim jester how to change static route and directory
nim linker error while linking to libsodium
Can countup and countdown iterators in Nim language be used in variable declaration?
How do I write unit test for code that should fail to compile in Nim?
Difference between void proc and void proc with discard
nim nimscript is not executing commands
Remove element at index from sequence
Is it possible / easy to include some mruby in a nim application?

Categories

HOME
go
httparty
codenvy
apache-flink
apache-jena
fpga
pagination
rdbms
jmx
fftw
mstest
sitecore
sublimetext
bookmarks
nuget-package
pkcs#11
arangodb
resultset
endpoint
favicon
frequency-distribution
zerobrane
event-sourcing
dynamic-sql
intershop
chargify
symfony-console
shortest-path
selinux
systemtime
epsilon
gpio
flooding
quantlib
testcomplete
aws-codecommit
kudu
memory-address
twos-complement
keras-layer
sendbird
reactjs.net
jwplayer6
alphabetical
ideascript
node-mssql
kill
numberpicker
portforwarding
http-request
placeholder
facebook-social-plugins
libgphoto2
facebook-pixel
mongotemplate
convex-optimization
context-switch
subnet
headless
cup
pdf-conversion
quicktime
bbpress
rackspace-cloud
polyline
x-tag
jboss-tools
wso2developerstudio
synonym
scaffolding
dimension
qiime
tracker-enabled-dbcontext
turbo-prolog
sklearn-pandas
maybe
state-restoration
vhosts
toran-proxy
assertion
dynatree
rewrite
pypiserver
oracle-spatial
doctype
nutiteq
apache-spark-1.3
ghcjs
contrast
formview
wcm
universal-image-loader
insight.database
grails-plugin-rabbitmq
jjaql
synapse
notorm
kendo-dataviz
asdf
ui-select2
jquery-1.9
diem
font-awesome-4.0.0
onload-event
curb
nokia-s40
update-statement
svk
updatesourcetrigger
globals
wcf-instancing
sun
dojo-dnd
appliance
pnrp

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App