fixed character length with a non-consistant variable length - Protocols
This is a discussion on fixed character length with a non-consistant variable length - Protocols ; I'm looking for a "simplier" way to force a variable of mixed character
length to a fixed character length.
For this project, I always want to have MORE characters than the actual
variable's size. So I'm trying to add in ...
-
fixed character length with a non-consistant variable length
I'm looking for a "simplier" way to force a variable of mixed character
length to a fixed character length.
For this project, I always want to have MORE characters than the actual
variable's size. So I'm trying to add in spaces. Thats my problem. Making it
less is easy.
Example from my project:
..q_formatted := \fstripx(\fsubstr(\m(getdata),1,13),\9)
The saved value has up to 13 characters, but mostly it has less.
For testing purposes, I'm trying to fixate the saved character length to 20.
The reasoning for doing this, is that I want to save a multitude of values
into 1 entry within an Array. And by it's character position, other macros
can determine what the value is represents.
The end result would be:
Characters 1-20 = First value
Characters 21-25 = Second value
Characters 26-30 = Thrid value
Characters 31-32 = Forth value
Characters 33-36 = Fifth value
Characters 37-40 = Sixth value
Characters 41-44 = Seveth value
I can technically do it, but I'm sure I'm going about it the wrong way.
Below is an example I just typed up. It wasn't tested yet.
All it does (or should do), is check for the length difference and use the
repeat function to add in spaces for the remainder.
..q_formatted := \fstripx(\fsubstr(\m(getdata),1,13),\9)
if < \flength(\fstripx(\fsubstr(\m(getdata),1,13),\9)) 20 {
..q_formatted :=
\m(q_formatted)\frepeat(\32,\feval(20-\flength(\fstripx(\fsubstr(\m(getdata),1,13),\9))) )
}
* I'm not at a computer which has the K95 system on it right now so that
example I just gave might have improper syntax. I can't recall if its
\frepeat(text,integer) or \frepeat(integer,text).
- Scott
-
Re: fixed character length with a non-consistant variable length
On 2007-01-19, Scott Caissie wrote:
:
: I'm looking for a "simplier" way to force a variable of mixed character
: length to a fixed character length.
:
: For this project, I always want to have MORE characters than the actual
: variable's size. So I'm trying to add in spaces. Thats my problem. Making
: it less is easy.
:
: Example from my project:
: .q_formatted := \fstripx(\fsubstr(\m(getdata),1,13),\9)
: The saved value has up to 13 characters, but mostly it has less. For
: testing purposes, I'm trying to fixate the saved character length to 20.
:
You can use \flpad() ("Left Pad") and/or \frpad() ("Right Pad") for this.
For example, suppose that if a string "foo" is less than 20 bytes long, you
want to fill it out on the right with underscores:
.foo := .\frpad(\m(foo),20,_)
If the string already is 20 or more bytes long, nothing happens to it.
To fill the string out with spaces, use either one of these forms:
.foo := .\frpad(\m(foo),20,\32)
.foo := .\frpad(\m(foo),20)
: The reasoning for doing this, is that I want to save a multitude of values
: into 1 entry within an Array. And by it's character position, other macros
: can determine what the value is represents.
:
You might find some of the programming and data-type extensions presented
here to be useful:
http://www.columbia.edu/kermit/ckscripts.html#oops
For example this one:
ftp://kermit.columbia.edu/kermit/scripts/ckermit/matrix
shows how to create and use multidimensional arrays.
- Frank