I am struggling with the concept of TaintedString in nim. I have scoured the forum and google but am finding very little.
This code works fine:
import strutils
var
inMod = false
texts = newSeq[string]()
s = ""
for line in lines r"../data/modules1.fhx":
if line.startsWith("MODULE_INSTANCE TAG="):
s = newStringOfCap(10000)
s.add(line & "\n")
inMod = true
elif inMod:
s.add(line & "\n")
if line.startsWith("}"):
inMod = false
texts.add(s)
echo texts.len
But this code has error:
import strutils
import sequtils
var
inMod = false
texts = newSeqWith(1400, string)
s = ""
for line in lines r"../data/modules1.fhx":
if line.startsWith("MODULE_INSTANCE TAG="):
s = newStringOfCap(10000)
s.add(line & "\n")
inMod = true
elif inMod:
s.add(line & "\n")
if line.startsWith("}"):
inMod = false
texts.add(s)
echo texts.len
The newSeqWith line has the following error: Error: type mismatch: got <type string> but expected 'TaintedString = string'
Please advise.
newSeqWith is usually used for creating 2D sequences, where you pass to it a function for creating inner sequences.
Here it seems to me that you wanted to initialize a sequence of string of initial length of 1400. If so, use newSeq[string](1400). (Later on, texts.add(s) should be replaced)
Thanks! I replaced texts.add(s) with texts[i] = s and it works now.
I am really loving nim... so glad you all made it to 1.0!