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

Is it possible / easy to include some mruby in a nim application?
Reading bytes from many files performance
Program doesn't compile when “concept” defines a method with a parameter
How do I create a directory?
Why is my string nil?
Nim code parser
What's the meaning of “magic” pragma in nim?
Unpack multiple variables from sequence
Nim: How to prove not nil?
Error: expression has no address
MD5 on an array, array[0..63, uint8] to cstring conversion
Converting a seq[char] to string
Nim: On mac, cannot open standard import
How to compare two typedesc in a template for equality
Is there a “default” file name that can be used for importing modules?
Unable to get StringStream created from marshal to output the data

Categories

HOME
uml
oracle12c
api
checkstyle
cheerio
mjml
numbers
alarm
opendj
polling
google-admin-sdk
octave
spring-social
dynatrace
template-engine
soci
foreign-keys
solrcloud
springfox
babel
react-toolbox
php-mysqlidb
event-store
google-api-client
exchangewebservices
jaws
constexpr
git-squash
reactjs.net
apiary.io
railstutorial.org
datacachefactory
escpos
snapchat
x++
phpdbg
getchar
openal
serde
spring-integration-sftp
reportservice2010
netbeans6.8
twilio-click-to-call
datamaps
zenhub
stdmap
modelsim
spring-data-couchbase
excel-dna
avx
flyout
rocks
slackware
windows-azure-queues
beamer
drawstring
eigenvector
mediametadataretriever
sklearn-pandas
html-to-pdf
asyncdisplaykit
jnlua
inf
character-replacement
binomial-theorem
cgi-bin
graphics2d
typeconverter
snackbar
zend-currency
cakephp-2.7
browserify-shim
cocos3d
parallel-testing
jjaql
scrypt
inputmismatchexception
windows-phone-8-sdk
route-provider
argouml
apache-commons-dbutils
cgbitmapcontextcreate
xui
codebase
application-verifier
purepdf
wysiwym
image-capture
commercial-application

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App