SPL Programming Exercise - Chapter 7 String and time
7.1 String
1. Given the string “I want to learn esProc SPL !”, the requirements are as follows:
(1) Calculate the length of the string
(2) Please change all letters in the string to uppercase
(3) Get the left 3 characters of the string
(4) Get the first to third to last characters of the string
(5) Get 5 characters to the right of the string
(6) Find the position of the string “esProc”
(7) Starting from the 3rd character of the string and get 7 characters forward
(8) Get the 10th character of the string to the end
(9) Remove the extra space before ‘!’ from the string
(10) Replace spaces in the string with “_”
2. Please check if each letter appearing in “boy” appears in the string “esProc SPL is a smart desktop data analysis tool”. If it appears, output true; otherwise, output false.
3. Concatenate the string “SPL” with “Structured Process Language” (implemented using different methods).
4. Concatenate the strings in the sequence [“apple”, “banana”, “orange”, “pear”, “cherry”] with numbers, and the concatenated effect will be [“apple_1”,“banana_2”,“orange_3”,“pear_4”,“cherry_5”]
5. Enter a name and a country, and output the sentence pattern “The world is so big, ()wants to go to () to have a look”. For example, input: “Xiao Ming” and “Egypt”, output: “The world is so big, Xiao Ming wants to go to Egypt to have a look.”
6. Print the multiplication table with the following effect:
1*1=1
1*2=2,2*2=4
1*3=3,2*3=6,3*3=9
……
1*9=9,2*9=18,3*9=27,4*9=36,5*9=45,6*9=54,7*9=63,8*9=72,9*9=81
7. Input the string of ID number, such as “330821198211126225”, and output in the following format:
You were born on November 12, 1982
You are 41 years old this year
Your gender is female
8. Write a program with the string “JanFebMarAprMayJunJulAugSepOctNovDec” to convert months to English abbreviations. Enter an integer between 1 and 12 and output its corresponding month abbreviation, such as 1 for Jan, 2 for Feb, etc.
9. Write a program to implement free conversion between Chinese yuan and US dollar. Enter currency and corresponding currency symbols from the keyboard. Automatically convert the input currency value to another currency value based on the input currency symbol. Assuming the exchange rate is fixed at 7.10
Input: ¥ 710
Output: 710 RMB can be exchanged for 100.0 USD
Input: $100
Output: 100 USD can be exchanged for 710.0 RMB
7.2 Split and merge
1. Given the string “1 SPL Means Structured Process Language 2 SPL is a smart desktop data analysis tool”, the requirements are as follows:
(1) Please change the uppercase of letters in the string to lowercase and lowercase to uppercase
(2) Please extract the numbers from the string and form a new string
(3) Please count the number of occurrences of the letter s in the string (ignoring case, s and S are the same letter)
(4) Please reverse the string and output it. Example: The inversion of “abc” is “cba”
(5) Extract words from the string
2. Enter a string and extract all even numbered characters to form a new string. Input “abcd1234” and output “bd24”.
3. Enter a string and count the number of non numeric and alphabetical characters in the string.
For example: Input ”anc2+93-sj 你好” Output: 4
4. There is a string in Excel as shown in the figure
Split it by “and” and separate the names of each fruit
5. There is a column of data in the Excel file that contains a mixture of characters and numbers, where numbers and characters may appear in multiple places with varying patterns of occurrence.
Require separating the numbers and characters in each row, placing the separated numbers in column B and the remaining characters in column C. The effect is shown in the following figure
6. There is a string as follows, with multiple key words, each with a corresponding value
Parse the keywords and their corresponding values, and the effect is shown in the following figure:
7. Practice merging multiple files with the same structure under a certain directory on your own.
7.3 Date and time
1. Obtain the current system time and the time at this moment in 3 days
2. Output the current system time in the format of “MMM-d-yy HH????ss”
3. Enter someone’s birthday in the format “yyyy-MM-dd” and calculate how many weeks have passed so far.
4. Define a time “2000-08-08 08:08:08” and determine whether this year is a regular year or a leap year
5. Set a lottery time, such as “November 11, 2024 10:00:00”, calculate the time interval between the current time and the lottery time, and in the form xx days xx hours xx seconds
6. Enter a certain year, month, and day, and find out which day of the year the input date is? For example, input 2023-03-05, calculate 31+28+5=64 days
7. Input the date “December 29, 2023”, which date will be 5 working days later?
8. Given a date and time ”yyyy-MM-dd hh????s”, calculate the date time value after n seconds (exceeding 23:59:59 is a new day).
9. There is a set of strings containing date information such as 6.5.18 and 18.7.19
“6.5.18 - no int in zone 1 but int in zone 2. 18.7.19 - summer update.”
Please extract the date section.
Suggested answers:
7.1 String
1.
A | |
---|---|
1 | I want to learn esProc SPL ! |
2 | =len(A1) |
3 | =upper(A1) |
4 | =left(A1,3) |
5 | =left(A1,-3) |
6 | =right(A1,5) |
7 | =pos(A1,“esProc”) |
8 | =mid(A1,3,7) |
9 | =mid(A1,10) |
10 | =trim@a(A1) |
11 | =replace(A1,““,”_”) |
2.
A | |
---|---|
1 | esProc SPL is a smart desktop data analysis tool |
2 | =len(A1).(mid(A1,~,1)).contain(“b”,“o”,“y”) |
3.
A | B | |
---|---|---|
1 | SPL | Structured Process Language |
2 | =A1+B1 | |
3 | =A1/B1 | |
4 | =concat(A1,B1) | |
5 | =pad(B1,A1,len(A1)+len(B1)) |
4.
A | |
---|---|
1 | =[“apple”,“banana”,“orange”,“pear”,“cherry”] |
2 | =A1.(~/“_”/#) |
5.
A | B | |
---|---|---|
1 | Xiao Ming | Egypt |
2 | >output(“The world is so big”+A1+“wants to go to”+B1+“to have a look”) |
6.
A | B | C | |
---|---|---|---|
1 | for 9 | ||
2 | for A1 | >output@s(B2/“*”/A1/“=”/${B2*A1}/if(B2==A1,"“,”,")) | |
3 | >output("") |
7.
A | B | |
---|---|---|
1 | =“330821198211126225” | 2023 |
2 | >output(“You were born on”/mid(A1,7,4)/“year”/mid(A1,11,2)/“month”/mid(A1,13,2)/“day”) | |
3 | >output(“You are”/${B1-number(mid(A1,7,4))}/“years old this year”) | |
4 | >output(“Your gender is”/if(number(mid(A1,-2,1))%2==0,“female”,“male”)) |
8.
A | |
---|---|
1 | 6 |
2 | JanFebMarAprMayJunJulAugSepOctNovDec |
3 | =mid(A2,(A1)*3-2,3) |
9.
A | B | |
---|---|---|
1 | ’$100 | |
2 | if left(A1,1)==“¥” | >output(right(A1,-2)/"RMB can be exchanged for"/(number(right(A1,-2))/7.1)/“dollar”) |
3 | elseif left(A1,1)==“$” | >output(right(A1,-2)/“USD can be exchanged for”/(number(right(A1,-2))*7.1)/“RMB”) |
4 | else | >output(“Input error”) |
7.2 Split and merge
1.
A | |
---|---|
1 | 1 SPL Means Structured Process Language 2 SPL is a smart desktop data analysis tool |
2 | =A1.split().(if(islower(~):upper(~),isupper(~):lower(~);~)).concat() |
3 | =A1.words@d().concat() |
4 | =A1.split().count(lower(~)==“s”) |
5 | =A1.split().rvs().concat() |
6 | =A1.words() |
2.
A | |
---|---|
1 | abcd1234 |
2 | =A1.split().select(#%2==0).concat() |
3.
A | B | |
---|---|---|
1 | anc2+93-sj 你好 | |
2 | =A1.split() | |
3 | for A2 | if !(A3 <= “z” && A3>=“a” || A3>=“A” && A3<= “Z” || A3>=“0” && A3 <= “9”) |
4.
A | |
---|---|
1 | =clipboard() |
2 | =A1.split(“and”).concat(“\t”) |
3 | >clipboard(A2) |
5.
A | |
---|---|
1 | =clipboard() |
2 | =A1.split(“\n”).(~.words@d().concat()/“\t”/(~.words@w()~.words@d()).concat()) |
3 | =A2.concat@n() |
4 | >clipboard(A3) |
6.
A | |
---|---|
1 | =clipboard() |
2 | =A1.property() |
3 | =file(“D://KV.xlsx”).xlsexport@tc(A2) |
7.3 Date and time
1.
A | |
---|---|
1 | =now() |
2 | =A1+3 |
2.
A | |
---|---|
1 | =now() |
2 | =string(A1,“MMM-d-yy HH????ss”) |
3.
A | |
---|---|
1 | 2006-10-25 |
2 | =interval(A1,now@d())\7 |
4.
A | |
---|---|
1 | 2000-08-08 08:08:08 |
2 | =year(A1) |
3 | =if(A2%4==0 && A2%100!=0 || A2%400==0,“Leap year”,"") |
5.
A | |
---|---|
1 | 2024 年 11 月 11 日 10 点 00 分 00 秒 |
2 | =A1.words@d() |
3 | =A2.to(3).concat(“-”)Regular year |
4 | =A2.to(4,).concat(“:”) |
5 | =A3+" "+A4 |
6 | =datetime(A5,“yyyy-MM-dd HH????ss”) |
7 | =long(A6)-long(now()) |
8 | =A7(24*60*60*1000) |
9 | =A7%(24*60*60*1000)\(60*60*1000) |
10 | =A7%(24*60*60*1000)%(60*60*1000)\(60*1000) |
11 | =A7%(24*60*60*1000)%(60*60*1000)%(60*1000)\1000 |
12 | >output(“距离抽奖时间还有”/A8/“天”/A9/“小时”/A10/“分”/A11/“秒”) |
6.
A | B | C | D | |
---|---|---|---|---|
1 | 2023-11-11 | =day(A1) | ||
2 | =year(A1) | =month(A1) | ||
3 | for B2-1 | if [1,3,5,7,8,10,12].contain(A3) | >B1+=31 | |
4 | elseif [4,6,9,11].contain(A3) | >B1+=30 | ||
5 | else | if A2%4==0 && A2%100!=0 || A2%400==0 | >B1+=29 | |
6 | else | >B1+=28 |
7.
A | B | |
---|---|---|
1 | 2023-12-29 | 5 |
2 | =workday(A1,B1,[date(“2024-01-01”)]) |
8.
A | |
---|---|
1 | 2023-11-11 23:59:58 |
2 | =elapse@s(A1,3) |
9.
A | |
---|---|
1 | 6.5.18 - no int in zone 1 but int in zone 2. 18.7.19 - summer update. |
2 | =A1.split(““).(date(~,“dd.MM.yy”)).select(~).concat(”;”) |
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL
Chinese version