Page 1 of 1
Posted: 24 Jul 2016, 22:55
by ahonoe
I'm trying to build a string from an array of ascii values using scripting. When I try to use the standard Pascal chr() function to convert the integers in my array, hh throws an "Unknown declaration "chr"" error. (BTW I do know that in hh a string is an arrays of chars.)
Thanks for your help!
Posted: 25 Jul 2016, 14:56
by oli_lab
Hi,
I'm fact you treat the char as single
Var currentChar: single
...
currentChar := GetdataArrayvalue(input, Idx );
...
SetdataArrayvalue (output, Idx, currentChar) ;
Posted: 25 Jul 2016, 18:39
by ahonoe
Thanks oli. What I am trying to do is build a complete string within the script before outputting it. Something like s:=s+chr(char_arr).
Thanks again.
Posted: 25 Jul 2016, 21:36
by shawnb
Concatenation works - the '+' operator.
In case you missed it, there's a very handy page on strings in the scripting language tutorial:
http://www.sensomusic.org/wiki3/doku.ph ... tutorial05
Look at the examples towards the bottom.
Posted: 26 Jul 2016, 06:11
by ahonoe
Thanks shawn. Yes I am familiar with this section of the tutorial. Appending chars to strings is clear to me. Maybe I'm missing something though.
To recap : I have an array of singles where each value represents an acsii character. I'm trying to convert this to a string. So I read each value in the array, round()ing it as I go. Now I want to convert each integer value to a char so I can append it to a string. In Pascal proper I'd use the chr() function but in hh that's not available. I guess my question really is how do I convert a single to a char.
Posted: 26 Jul 2016, 06:49
by shawnb
I don't do a lot of string manipulation, so I can only tell you what I'd try...
There are three approaches I'd experiment with...
(1) Your example with a recast along the way... s := s+inttostr(char_arr);
(2) Loop StrSet's, e.g., StrSet(char_arr, x, s); Don't forget to do a SetLength somewhere in there
(3) Declare char_arr as a string to begin with
Dealing with small integers you may need to recast using trunc() or int() somewhere along the line...
Shawn
Posted: 26 Jul 2016, 18:21
by oli_lab
Maybe simply
S := S + ArrChar ?
Posted: 26 Jul 2016, 18:51
by ahonoe
shawnb:
1) appends the ascii value to my string rather than the acsii character
2) StrSet() looks interesting however hh throws an "Unknown declaration "StrSet"" error. Maybe this procedure hasn't been implement in hh?
3) char_arr is, by functional requirement, an array of singles though the values at the relevant index are always converted to integers (as they are ascii vals)
oli:
Same problem as #3 above. The array values are singles and can't be added to a string.
Thanks again for your suggestions. I do appreciate them.
Posted: 26 Jul 2016, 19:06
by oli_lab
I remember having trouble with char and string with script in the past, I think I find it easier with the sdk.
I'll check in my archive for script I made using char and string...
Posted: 26 Jul 2016, 20:17
by senso
hi,
you're right the CHR is missing in the script engine. It will be corrected in the next major release.
the work arround is to create the CHR function yourself like bellow. Fully customizable
senso+++
Code: Select all
function MyCHR(i:integer):Char;
const S ='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
begin
result := S[i-40];
end;
//////////////////////////////
// main proc
//////////////////////////////
Procedure Process;
begin
writeln(MyChr(41)+MyChr(42));
end;
Posted: 27 Jul 2016, 15:32
by ahonoe
Thanks oli and Olviier. I've worked around the issue by writing the chrs to, then reading them back from, a ptString output.