Given a list of small strings (1 to 3 words each), I would like to print them in 2 columns using ZPL for Zebra Printers. For example, if the list is ["A", "B", "C", "D", "E"], I would like my label to look like this:
A B
C D
E
However, if strings are a little bit longer, I would like to be able to truncate them so that columns don't overlap. For example, if the list is ["string 1", "string 2", "long string 3", "string 4", "string 5"], the label should look like this:
string 1 string 2
long str string 4
string 5
I see 2 possible approaches to this:
1) Using some ZPL command that I have not been able to find yet
2) Calculating the width of the strings in pixels. In this case I would need to know what is the font used by ZPL.
I'm using this command for text printing:
^A0,N,30,30
^FDtext^FS
It looks like ^TB is the solution:
^A0N,30,30
^TBN,250,29
^FDtext should go here^FS
Related
how do I split string by space and following specific number? My string looks like
PID55688.00976 1
PID66854.76557 2
PID88774.23455 3
PID66843.99754 1
PID66800.00764 3
I want to split string by space and number 3
Code
str.split(/\s3/) does not split anything.
This produces the expected output that OP has describe in the comments on #spickermann's answer:
string = <<-STRING
PID55688.00976 1
PID66854.76557 2
PID88774.23455 3
PID66843.99754 1
PID66800.00764 3
STRING
string.split(/ 3\n/).map{|substring| (substring+" 3").split(/\n/)}
but there's some typos in OP's expected answer, as there's no commas or quotes in the arrays. So I might have misinterpreted.
I would do something like this:
string = <<-STRING
PID55688.00976 1
PID66854.76557 2
PID88774.23455 3
PID66843.99754 1
PID66800.00764 3
STRING
string.scan(/(\w+\.\w+ \w+)\n/).flatten
#=> [["PID55688.00976 1"], ["PID66854.76557 2"], ["PID88774.23455 3"], ["PID66843.99754 1"], ["PID66800.00764 3"]]
Assuming
[["PID55688.00976 1", "PID66854.76557 2", "PID88774.23455 3"],
["PID66843.99754 1", "PID66800.00764 3"]]
is the desired return value, one could write:
string.split(/\r?\n/).slice_after { |s| s.end_with?(' 3') }.to_a
See Enumerable#slice_after and String#end_with?.
I am making a program which takes user input and handles that input based on the user's choice of options. Say I input a string like "hello 4 is a number, and 5 is as well". How can I take the numbers from the string and put them in variables? (In my example I am looking to use the 4 and 5.)
So, i write some code to solve your problem. First and easyest case: you pass the sentence as a list, like this [hello,4,is,5,and]. In this case, you need to check if an element of the list is a number with number/1:
parseSentence([],[]).
parseSentence([H|T],L):-
\+(number(H)),
parseSentence(T,L).
parseSentence([H|T],[H|T1]):-
number(H),
parseSentence(T,T1).
?- parseSentence([hello,4,is,5,and],L).
L = [4, 5].
false
Second and most interesting case: you pass the sentence as a string, like this: "hello 4 is a number, and 5 is as well". Here the code (a bit redundant to make it more clear):
parseSentenceMod([],[]).
parseSentenceMod([H|T],[A|T1]):-
atom_number(H,A),
parseSentenceMod(T,T1).
parseSentenceMod([H|T],L):-
\+(atom_number(H,_)),
parseSentenceMod(T,L).
findAtom([],[]).
findAtom([H|T],[H1|T1]):-
atom_string(H1,H),
findAtom(T,T1).
parseString(S,P,A,N):-
split_string(S," ","",P),
findAtom(P,A),
parseSentenceMod(A,N).
?- parseString("hello 4 is a number, and 5 is as well",S,A,N).
A = [hello, '4', (is), a, 'number,', and, '5', (is), (as), well],
N = [4, 5],
S = ["hello", "4", "is", "a", "number,", "and", "5", "is", "as", "well"]
false
atom_number/2 checks if the atom is a number, atom_string/2 creates an atom given a string and split_string/4 splits the string in substrings separated by, in this case, a blank space. Hope it helps.
I was wondering if there is a way to accomplish the following.
There is a label in AX, lets call it #SYS123 which contains the following value: The sum of {1} and {2} is {3}.
I would like to use this label in a SSRS expression and was thinking in this direction: =System.String.Format(Labels!#SYS123, "4", "5", "9")
But this just gives me #Error.
Is there a way to do this or do I need to concatenate the strings and values to get the desired output?
The reason I would like to make use of the Label is multilanguage support.
Any input is appreciated
Create label with value: The sum of {0} and {1} is {2}.
Composite format string is 0-based.
I want to make tabular output in Ruby...
I am using puts "x\t\t[OK]
assuming that x represents inputted filename, and this process is repeated for ever, and assuming that the range of characters is from 5 - 20 characters the output won't be neat
Output sample: http://pastebin.com/kwJ9ajqj
I want the OKs to be aligned.
You can fill the x-s with spaces to the same (maximum) length using ljust.
xs = [ "short", "longer string", "even a bit longer" ]
xs.each { | x | puts "#{x.ljust(20)} [OK]" }
This will align the "[OK]"s. If you need tabs, you can insert them
after filling like
puts "#{x.ljust(20)}\t\t[OK]"
Use printf-style formatting:
printf("%20s %s", filename, (ok ? '[OK]' : '[FAILED]'))
I am having quite the difficulty using regex in ruby to split a string along several delimiters these delimiters are:
,
/
&
and
each of these delimiters can have any amount of white space on either side of the delimiter but each item can contain a valid space.
a great example that I've been testing against is the string 1, 2 /3 and 4 12
what I would like is something around the lines of "1, 2 /3 and 4 12".split(regex) =>["1", "2", "3", "4 12"]
The closest I've been able to get is /\s*,|\/|&|and \s*/ but this generates ["1", " 2 ", "3 ", "4 12"] instead of the desired results.
Realize this is very close and I could simply all trim on each item, but being so close and knowing it can be done is sort of driving me mad. Hopefully someone can help me keep the madness at bay.
/\s*,|\/|&|and \s*/
This parses as /(\s*,)|\/|&|(and \s*)/. I.e. the leading \s* only applies to the comma and the trailing \s* only applies to "and". You want:
/\s*(,|\/|&|and )\s*/
Or, to avoid capturing:
/\s*(?:,|\/|&|and )\s*/
Try .scan:
irb(main):030:0> "1, 2 /3 and 4 12".scan(/\d+(?:\s*\d+)*/)
=> ["1", "2", "3", "4 12"]
You can try:
(?:\s*)[,\/](?:\s*)|(?:\s*)and(?:\s*)
But as Nakilon suggested, you may have better luck with scan instead of split.