The current raw data :
1-2-05.11
1-15-05.20
how can I remove after .. The expected result is 1-2-05. I test using split_part and also substring, but the result is not fit the requirement.
Any suggestion ?
Try this,I assume that your expected output is 1-2-05.(with .)
Using split_part().
SELECT SPLIT_PART('1-2-05.11','.',1)||'.';
Using substring().
SELECT SUBSTRING('1-15-05.20', 1, LENGTH('1-15-05.20') - 2)
1 is the starting position(from left) of the string(1-15-05.20) in which substring action to be taken
LENGTH('1-15-05.20') - 2, is to define the number of character to be extracted from the given string.The string is 1-15-05.20 the length() of it is 10, you need to remove last two characters from this 10 chars so 10 - 2 ie LENGTH('1-15-05.20') - 2
Related
I want to extract a number that follows a specific string ':' and write a code that adds that number. I think.. can split it by space and extract it from it... Well, it doesn't work.
1.(12321 6,80.0:3 210.1:3!!!73 540.2:1++ 96.3:3!<<<<%% 689.4:3 24.5:4)
I want to extract the number 3 3 1 3 3 3 4 followed by ":" from this string and find out that the sum is 17.
import re
var1 = '1.(12321 6,80.0:3 210.1:3!!!73 540.2:1++ 96.3:3!<<<<%% 689.4:3 24.5:4)'
item = var1.split(" ")
sum([int(i) for i in re.findall('(?<=:)\\d+',var1)])
17
For the following list:
q)a:("ua#1100#1";"sba#2220#2";"r#4444#a")
I want following output :
("1100#1";"2220#2";"4444#a")
? gives first index of #
q)(a?\:"#")
2 3 1`
but using cut does not give the desired result :
q)(a?\:"#")cut'a
(("ua";"#1";"10";"0#";"1");("sba";"#22";"20#";"2");("r";"#";"4";"4";"4";"4";"#";"a"))`
You can also parse the data rather than drop chars from each string.
It'll be somewhat more efficient if your dataset is large.
q)("J#*"0:/:a)[;1]
"1100#1"
"2220#2"
"4444#a"
Notice I've set the 'key' to 'J' which will result in nulls in your example case, but you only care about the values anyway.
If you can join (sv) the strings together, it'll be even better too
q)last "J#;"0:";" sv a
"1100#1"
"2220#2"
"4444#a"
HTH,
Sean
When the left argument of cut is atom , cut behaves differently than _.
q)2 cut 2 3 4 5 6
(2 3;4 5;,6)
q)2 _ 2 3 4 5 6
4 5 6
Use _ to cut the string
q)(1+a?\:"#")_'a
("1100#1";"2220#2";"4444#a")
or
q)"#"sv/:1_/:"#" vs/:a
("1100#1";"2220#2";"4444#a")
I have already used the text delimiters and item numbers to extract a date from a file name, so I'm clear about how to use these. Unfortunately the date on these particular files are formatted as "yyyyMMdd" and I need to covert the date into format "yyyy-MM-dd". I have been trying to use the offset function to get particular index positions, and I have found several examples of how you would return the offset of particular digits in the string, example:
set theposition to offset of 10 in theString -- this works
(which could return 5 or 7) but I have not found examples of how to call the digits at a specific index:
set _day to offset 7 of file_date_raw -- error
"Finder got an error: Some parameter is missing for offset." number -1701
How would you do this, or is there a totally better way I'm unaware of?
To "call the digits at a specific index", you use:
text 1 thru 4 of myString
If you know that each string has 8 characters in the yyyymmdd format, then you don't need to use 'offset' or any parsing, just add in the -'s, using text x thru y to dissect the string.
set d to "20011018"
set newString to (text 1 thru 4 of d) & "-" & (text 5 thru 6 of d) & "-" & (text 7 thru 8 of d)
I have a table field where the data contains our memberID numbers followed by character or character + number strings
For example:
My Data
1234567Z1
2345T10
222222T10Z1
111
111A
Should Become
123456
12345
222222
111
111
I want to get just the member number (as shown in Should Become above). I.E. all the digits that are LEFT of the first character.
As the length of the member number can be different for each person (the first 1 to 7 digit) and the letters used can be different (a to z, 0 to 8 characters long), I don't think I can SPLIT the field.
Right now, in Power Query, I do 27 search and replace commands to clean this data (e.g. find T10 replace with nothing, find T20 replace with nothing, etc)
Can anyone suggest a better way to achieve this?
I did successfully create a formula for this in Excel...but I am now trying to do this in Power Query and I don't know how to convert the formula - nor am I sure this is the most efficient solution.
=iferror(value(left([MEMBERID],7)),
iferror(value(left([MEMBERID],6)),
iferror(value(left([MEMBERID],5)),
iferror(value(left([MEMBERID],4)),
iferror(value(left([MEMBERID],3)),0)
)
)
)
)
Thanks
There are likely several ways to do this. Here's one way:
Create a query Letters:
let
Source = { "a" .. "z" } & { "A" .. "Z" }
in
Source
Create a query GetFirstLetterIndex:
let
Source = (text) => let
// For each letter find out where it shows up in the text. If it doesn't show up, we will have a -1 in the list. Make that positive so that we return the index of the first letter which shows up.
firstLetterIndex = List.Transform(Letters, each let pos = Text.PositionOf(text, _), correctedPos = if pos < 0 then Text.Length(text) else pos in correctedPos),
minimumIndex = List.Min(firstLetterIndex)
in minimumIndex
in
Source
In the table containing your data, add a custom column with this formula:
Text.Range([ColumnWithData], 0, GetFirstLetterIndex([ColumnWithData]))
That formula will take everything from your data text until the first letter.
What should be the read format of the of following dataset in fortran. there are 6 spaces between column 1 and 2 with no space of column 1 from margin.
1911.01.01 2.42873702403226
1911.01.02 3.5057043827303
1911.01.03 2.73602527398387
1911.01.04 6.07213767208333
1911.01.05 6.94818901068145
1911.01.06 3.66986589769583
1911.01.07 1.94565994542339
1911.01.08 2.39384275272177
1911.01.09 3.05526130775417
1911.01.10 2.69990836499194
1911.01.11 6.08406263835833
1911.01.12 7.34200241064516
1911.01.13 2.42873702403226
1911.01.14 3.5057043827303
1911.01.15 2.73602527398387
1911.01.16 6.07213767208333
1911.01.17 6.94818901068145
1911.01.18 3.66986589769583
1911.01.19 1.94565994542339
1911.01.20 2.39384275272177
1911.01.21 3.05526130775417
1911.01.22 2.69990836499194
1911.01.23 6.08406263835833
1911.01.24 7.34200241064516
1911.01.25 2.42873702403226
1911.01.26 3.5057043827303
1911.01.27 2.73602527398387
1911.01.28 6.07213767208333
1911.01.29 6.94818901068145
1911.01.30 3.66986589769583
1911.01.31 1.94565994542339
I tried.....
format (i4,i2,i2,6x,d9.14)
but it didnt work
thanks in advance
elisa
So try
(i4,a1,i2,a1,i2,6x,d16.14)
I think you've made two mistakes:
Not accounting for the . characters in the dates, I don't think that they will automatically be treated as field separators (as , or spaces would be). Obviously you'll want to ignore them.
In your d edit descriptor the number of decimal digits, that is the number after the . ought to be no greater than the total field width, ie the number before the ..