forum-msg-id-133385-edit

Original date:2019-01-10 07:31:44 Edited by: ChrisB Subject: Re: Using insert()

alrobnett said...

Goal: To create a file to store an extracted selected subtree having appropriate name. Each descriptor is 12 characters long.

integer node_descriptor_loc 
sequence UCTree -- entire file of descriptors 
sequence extract_path 
 
      node_descriptor = UCTree[node_descriptor_loc .. node_descriptor_loc + 11]  
      extract_path = insert("UCT.dat", node_descriptor, 4) 
      open({extract_path}, "wb") 



Problem: 'open' statement results in error: "character string contains a sequence" (refers to extract_path)

Tried using quotes "node_descriptor"
No luck

When you get the error sequence inside character string, you've always put a sequence in a sequence. So what you have done is inserted the sequence "UCT.dat" into the sequence node descriptor. Lets say node_descriptor is "ThisIsMyNodeDescriptor", then what you have created is "This"UCT.dat"MyNodeDescriptor" - or to look at it another way

T                 -one character is a sequence of 1 
h 
i 
s 
UCT.dat           -this is the sequnce you inserted 
M 
y 
N 
and so on 

I have done this so many times, believe me you are not alone. Splice and insert are very good sequence manipulators, but sometimes it makes the code clearer if you simplify even further. First create you individual bits of the string you want to create, and then & them together. so, for instance, using the above example

sequence str1, str2, str3, node_descriptor 
 
node_descriptor = "ThisIsMyNodeDescriptor" 
str1 = node_descriptor[1..4] 
str2 = node_descriptor[5..$] 
 
node_descriptor = str1 & "UCT.dat" & str2 
 
--I often do this in puts to add a line feed 
puts(, node_descriptor & "\n" 
 

Cheers

Chris

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu