9.6 Split string into a sequence of characters
Split a string and generate a sequence of characters.
Find the number of commas, excluding those in brackets, in the source code of a certain web page. Below is part of the content of the web page source code:
<html>
<b></b>
<table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)">
<colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /><col /><col /></colgroup>
<thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th></tr></thead>
…
A.split() function can split a string into a sequence of characters.
SPL script:
A | B | C | |
---|---|---|---|
1 | =file(“code.html”).read() | ||
2 | =A1.split() | 0 | 0 |
3 | for A2 | if A3==“[” | =B2+=1 |
4 | else if A3==“]” | =B2-=1 | |
5 | else if A3==“,”&&B2==0 | >C2+=1 |
A1 Read string from the file.
A2 Use A.split() function to split strings into a sequence of characters.
B3~C3 A left bracket appears and add 1 to B2 to match this bracket.
B4~C4 A right bracket appears and subtract 1 from B2 to match this bracket.
B5~C5 When a comma appears and the bracket matches, add 1 to C2’s count. C2 is the number of commas outside brackets.
Execution result:
A2:
Members |
---|
< |
h |
t |
m |
… |
C2:
Value |
---|
27 |
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