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

Unable to build nimsuggest
Nim: How to check if a float is nan or inf?
How to help nim prove that indices from an iterator are disjoint (within parallel section)?
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

Categories

HOME
httparty
time-complexity
character-encoding
pascal
obfuscation
vscode-extensions
opendj
vxml
zip
spring-session
flume
commonjs
vimdiff
activecollab
redis-sentinel
3nf
altera
dynamic-sql
powershell-v5.0
aws-sdk
feathersjs
sencha-touch
user-experience
systemtime
r-mice
string-concatenation
imageresizer
hta
direct3d11
interbase
mat
rpgle
bringtofront
finagle
gitlab-api
dst
deltaspike
catch-unit-test
mailkit
mnist
processwire
searchkit
timing
odroid
unordered-map
install.packages
jquery-ui-draggable
spring-integration-sftp
cvxpy
flex-monkey
spring-cloud-feign
dup
tooleap
observablecollection
spreadjs
upx
jparsec
httpruntime.cache
linklabel
themoviedb-api
iokit
file-move
forwarding
include-guards
finalbuilder
ocra
skspritenode
teamcity-9.1
fail2ban
dbaccess
theos
wcm
grails-plugin-rabbitmq
breakout
video-codecs
monotouch.dialog
appjs
cgimage
agility.js
mysql-error-1205
automationelement
clrstoredprocedure
hbm2java
application-verifier
zen
wordprocessingml
pnrp

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