There is a list of values, the first number represents the parent, the second number represents the child. e.g.
1,8
1,9
1,10
2,3
22,8
22,13
This is where I'm having problems. If these values are stored in a file, line by line as shown, how would I select e.g. the no.22? Would I have to split it when it finds the comma or is there a simpler way because it took me a while to figure out line[0] wouldn't work for 2 digit numbers if I read line by line.
Related
The following code gives a repeating sequence of specified numbers from 1 to 12, repeating it 12 times. However, the numbers generated have a different length (1,2,3...10,11,12). How can the formula be modified so that leading zeros are added in order to make all numbers the same length?
transpose(split(REPT(concat(JOIN(",",SEQUENCE(1,12)),","),ROUNDDOWN(ROWS(A1:A)/15)),",",true))
For example, in this example there are numbers with length = 2 and then the desired sequence would be 01,02...10,11,12. However if the sequence was up to 3 or more digits, for example:
...(",",SEQUENCE(1,150)),",")...
Then a desired sequence would be 001...010...150. A sequence going up to 4 would be 0001...1500 etc.
try:
=INDEX(TEXT(FLATTEN(MAKEARRAY(25, 12, LAMBDA(x, y, y))), "00"))
BASE formula has min_length argument. You can use it to set the LENgth of your sequences. It's also easy to create the sequence without TRANSPOSE/SPLIT/JOIN/SPLIT with just IF/FLATTEN. For eg, To create sequence of 12, 25 times,
=ARRAYFORMULA(FLATTEN(IF(SEQUENCE(25),BASE(SEQUENCE(1,12),10,LEN(12)))))
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 have a config.txt file having data in the following format
2
B 6.5 5001
F 2.2 5005
The first line of this file indicates the number of neighbors for Router A. Following this, there is one line dedicated to each
neighbor. It starts with the neighbor ID, followed by the cost to reach this neighbor and finally the port number that this neighbor is using for listening.
I am trying to implement bellman-Ford routing algorithm and for that I am passing this file as command line argument.
I want to make it into a list in order to store it into a data structure for later use but I am not sure whether the list would contain only 3 elements i.e the 3 lines?
Or I need to split each string by whitespace/store each string in every line separated by whitespace, into a list.
I am able to use split function to make a list of the 3 lines but how do I make a list of the strings/characters within a line?
Well, you can always do a double-split - first by line, then by whitespace:
data = """2
B 6.5 5001
F 2.2 5005"""
parsed = [line.split() for line in data.split("\n") if line]
# [['2'], ['B', '6.5', '5001'], ['F', '2.2', '5005']]
You can then iterate through it and convert your fields to whatever you need.
I have a need in SAPScript to trim a string from the right. There doesn't appear to be a function to accomplish this. &myfield+3& only trims from the left.
Is there a way to trim from the right? Can offset accept a negative value?
My ultimate goal was to take a number such as a quantity; 12.43 and convert that to: 001243.
6 characters long
padded left with zeroes
no special characters (decimals or thousands separators)
Ultimately I had to first define a field and do the intial number formatting:
/:DEFINE &myfield& = &qtyfield(.2CT)&
The above
sets the number to 2 decimal points (.2)
space compreession (C)
removes the thousands separator (T)
Then I call a function within our print routine to do the special character stripping as such:
/:PERFORM get_unformatted_value IN PROGRAM zbc_rle_ean128_label
/:USING &myfield&
/:CHANGING &myfield&
/:ENDPERFORM
Then I can do the final output as such:
/ &myfield(K6RF0)&
which:
Ignores any conversions (K)
Sets output length to 6 and right aligns it (6R)
and left pad with zeros (F0)
That seems to work for me. Hopefully this helps someone!
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