I am creating a scrollable list using ncurses, similar to the list in aptitude (apt-get front end).
How should I go about creating padded spaces between columns? I am planning to write each column using wprintw().
e.g.
pizza spicy 10
steak normal 10
burritoes guacamole 20
each line using wprintw().
The following will give you 2 space padded, left justified, string columns 10 characters wide, each followed by a space, then a 2 digit decimal column.
wprintw(win,"%-10s %-10s %2d\n", "pizza", "spicy", 10);
Related
I'd need to split or extract only numbers made of 8 digits from a string in Google Sheets.
I've tried with SPLIT or REGEXREPLACE but I can't find a way to get only the numbers of that length, I only get all the numbers in the string!
For example I'm using
=SPLIT(lower(N2),"qwertyuiopasdfghjklzxcvbnm`-=[]\;' ,./!:##$%^&*()")
but I get all the numbers while I only need 8 digits numbers.
This may be a test value:
00150412632BBHBBLD 12458 32354 1312548896 ACT inv 62345471
I only need to extract "62345471" and nothing else!
Could you please help me out?
Many thanks!
Please use the following formula for a single cell.
Drag it down for more cells.
=INDEX(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "))=8,
SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "),"")),"where Col1 is not null ",0)))
Functions used:
QUERY
INDEX
TRANSPOSE
IF
LEN
SPLIT
REGEXREPLACE
If you only need to do this for one cell (or you have your heart set on dragging the formula down into individual cells), use the following formula:
=REGEXEXTRACT(" "&N2&" ","\s(\d{8})\s")
However, I suspect you want to process the eight-digit number out of all cells running N2:N. If that is the case, clear whatever will be your results column (including any headers) and place the following in the top cell of that otherwise cleared results column:
=ArrayFormula({"Your Header"; IF(N2:N="",,IFERROR(REGEXEXTRACT(" "&N2:N&" ","\s(\d{8})\s")))})
Replace the header text Your Header with whatever you want your actual header text to be. The formula will show that header text and will return all results for all rows where N2:N is not null. Where no eight-digit number is found, null will be returned.
By prepending and appending a space to the N2:N raw strings before processing, spaces before and after string components can be used to determine where only eight digits exist together (as opposed to eight digits within a longer string of digits).
The only assumption here is that there are, in fact, spaces between string components. I did not assume that the eight-digit number will always be in a certain position (e.g., first, last) within the string.
Try this, take a look at Example sheet
=FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8)
Or this to get them all.
=JOIN(" ,",FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8))
Explanation
SPLIT with the dilimiter set to " " space TRANSPOSE and FILTER TRANSPOSE(SPLIT(B2," ") with the condition1 set to LEN(TRANSPOSE(SPLIT(B2," "))) is = 8
JOIN the outputed column whith " ," to gat all occurrences of number with a length of 8
Note: to get the numbers with the length of N just replace 8 in the FILTER function with a cell refrence.
Using this on a cell worked just fine for me:
(cell_with_data)=REGEXEXTRACT(A1,"[0-9]{8}$")
I want to implement a text drawing function. But I am not sure how \t works, which means I don't know how many spaces I should print for \t.
I have come up with the following algorithm:
a) Each \t represents at most NUMBER_OF_SPACES_FOR_TAB spaces.
b) If \t appears in the last line at a corresponding position, \t for this line should be aligned to the \t of last line.
Example:
printf("a\t\tb\n");
printf("\t\tc\n");
Should print:
a11112222b
34444c
Where:
1.Number i represents the spaces of \t at position i
2.NUMBER_OF_SPACES_FOR_TAB == 4
Does anyone know the standard algorithm? Thanks in advance.
A tab character should advance to the next tab stop. Historically tab stops were every 8th character, although smaller values are in common use today and most editors can be configured.
I would expect your output to look like the following:
123456789
a b
c
The algorithm is to start a column count at zero, then increment it for each character output. When you get to a tab, output n-(c%n) spaces where c is the column number (zero based) and n is the tab spacing.
Imagine a ruler with tab stops every 8 spaces. A tab character will align text to the next tab stop.
0 8 16 24 32 40
|.......|.......|.......|.......|.......|
printf("\tbar\n"); \t bar
printf("foo\tbar\n"); foo\t bar
printf("longerfoo\tbar"); longerfoo\t bar
To calculate where the next tab stop is, take the current column.
nextTabStop = (column + 8) / 8 * 8
The / 8 * 8 part effectively truncates the result to the nearest multiple of 8. For example, if you're at column 11, then (11 + 8) is 19 and 19 / 8 is 2, and 2 * 8 is 16. So the next tab stop from column 11 is at column 16.
In a text editor you may configure tab stops to smaller intervals, like every 4 spaces. If you're simulating what tabs look like at a terminal you should stick with 8 spaces per tab.
A Tab character shifts over to the next tab stop. By default, there is one every 8 spaces. But in most shells you can easily edit it to be whatever number of spaces you want (profile preferences in linux, set tabstop in vim).
I have a text column in PowerBI, with numeric digits separated by a hyphen. I need the left side to be exactly 5 digits. If it is less, then add leading zeros. The right side needs to be 4 digits. Any less, add leading zeros.
For example:
0002-800 -> 00002-0800
0001-0800 -> 00001-0800
12345-220 -> 12345-0220
Any help is appreciated.
Thanks
Edit the query. Let's assume the text is in a column called "code".
Split the column by delimiter, using the dash as the delimiter
Create a new column that pads the code.1 with 0 if its length is less than 5, else use code.1
Create a new column that pads the code.2 with 0 if its length is less than 4, else use code.2
append the two helper columns with a dash in between
remove the code and helper columns and rename the remaining column to your liking.
Text.Length will return the length of a string, Text.PadStart() will pad text. The formula for step 3 above is
if Text.Length([code.1]) < 5 then
Text.PadStart([code.1], 5, "0")
else
[code.1])
You can do this with one step:
= Table.TransformColumns(
Source, {"Column", each Text.Combine({
Text.PadStart(Text.BeforeDelimiter(_, "-"),5,"0"),
Text.PadStart(Text.AfterDelimiter(_, "-"),4,"0")
},"-"
),type text}
)
A B C D
2 DRUGS 000000000004 2 PARACETAMOL (ACETAMINOPHEN) TAB 500 MG
This is my entry in my open office so we have here the row 2 with columns A-D
I have create a formula =CONCATENATE("('" ;A2;"','";B2;"','";C2;"','";D2;"'),")
and this one give me this result:
('DRUGS','4','2','PARACETAMOL (ACETAMINOPHEN) TAB 500 MG'),
Basically I want a result like:
('DRUGS','000000000004','2','PARACETAMOL (ACETAMINOPHEN) TAB 500 MG'),
Column B is set to Number with Leading zeroes set to 12.
What I want is to get a result where the leading zeroes in column B is will retained.
=CONCATENATE("('" ;A2;"','";TEXT(B2;"000000000000");"','";C2;"','";D2;"'),")
Use any mask you want as the second parameter to the TEXT function
More on TEXT and other text functions: https://help.libreoffice.org/Calc/Text_Functions#TEXT
Please try:
=CONCATENATE("('";A2;"','";REPT("0";12-LEN(B2));B2;"','";C2;"','";D2;"'),")
I suspect what you have in B2 is 4 formatted with many leading 0. If so, it is possible, assuming many other entries, that some will be text and the cell content actually something like 000000000004 - for which the above formula will not work (but yours should).
I have 6 fields in a row in open office, the 1st is a word, the 2nd, 3rd, and 4th are a number with a leading zero, the 5th and 6th are regular numbers. How do I join them all together with a comma between them so that the leading zero stays?
Based on your comment about your numbers having a leading 0 in virtue of a custom number format, you need to incorporate TEXT() functions into your formula to retain (i.e., add) your leading 0s.
=CONCATENATE(A1,",",TEXT(B1,"0#####"),",",TEXT(C1,"0#####"),",",TEXT(D1,"0#####"),",",E1,",",F1)
Just be sure to include as many #'s as the max length of a number in that field.
Please try:
=A1&",0"&B1&",0"&C1&",0"&D1&","&E1&","&F1