[英]Javascript Delete First Character on Each Line of String
I need to remove the first character of a string "|"我需要删除字符串“|”的第一个字符on each line in javascript.
在 javascript 的每一行上。
| D| Gbm| G| A|
| D| Gbm| G| A|
| Bm| Gbm| G| D|
| Bm| Gbm| G| A|
| D| Gbm| G| A|
| D| Gbm| G| A|
| Bm| Gbm| G| D|
| Bm| E| G| G A|
| D| Gbm|
end results needed:需要的最终结果:
D| Gbm| G| A|
D| Gbm| G| A|
Bm| Gbm| G| D|
Bm| Gbm| G| A|
D| Gbm| G| A|
D| Gbm| G| A|
Bm| Gbm| G| D|
Bm| E| G| G A|
D| Gbm|
This is the page I need to edit to get just the chords.这是我需要编辑以获取和弦的页面。 I removed the quotes with
我删除了引号
tOut = tOut.replace("\"", "");
http://www.lesession.co.uk/abc/abcChordsOut.htm This is the text input in ABC Notation format: http://www.lesession.co.uk/abc/abcChordsOut.htm这是ABC Notation格式的文本输入:
X:1
T:Guitar
L:1/8
K:D
Q:1/4=120
R:Medium Boogie
M:4/4
| "D"D,2 A,,D, D,2 [C,A,,]_B,,/2=B,,/2 | "Gbm"_G,,3 _G,,/2E,,/2 _G,,2 _D,/2=D,/2_E,/2=E,/2 | "G"G,3 G, G,3 =G,, | "A"A,,3 A,, A,,2 B,,2 |
| "D"A,,3 =D,/2A,,/2 D,2 F,G, | "Gbm"_G,,3 _G,,/2E,,/2 _G,,2 _D,_G,, | "G"=G,,3 G,,/2E,,/2 G,,2 B,,=D, | "A"A,2 G,A, A,E, A,,2 |
| "Bm"B,,2 =C,B,,/2A,,/2 B,,2 A,,2 | "Gbm"_G,3 _G,/2=F,/2 _G,2 _D,2 | "G"=G,3 =D, G,2 A,2 | "D"[D3^G,3] D D2 B,/2C/2A,/2^C,/2=C,/2 |
| "Bm"B,,3 B,,/2A,,/2 B,,3 F,,/2E,,/2 | "Gbm"_G,,3 _G,, E,,/2_G,,3/2 A,,_D, | "G"=G,,3 G,,/2E,,/2 G,,2 B,,/2G,,/2_B,,/2^G,,/2 | "A"A,,3 A,, A,,A,,=B,,C, |
| "D"D,3 D,/2A,,/2 D,2 A,2 | "Gbm"_G,,3 _G,,/2=F,,/2 _G,,3 E,, | "G"=G,,3 G,,/2E,,/2 G,,2 B,,3/2=C,/2 | "A"A,,4 z4 |
| "D" z3/2 B,,/2 ^C,D, A,,/2D,3/2- D,3/2A,/2 | "Gbm"_G,,3 _G,, E,,/2_G,,3/2 A,,_D, | "G"=G,,3 G,,/2E,,/2 G,,2 _B,,=D, | "A"A,,3 A,, A,,2 E,,2 |
| "Bm"B,2 B,2 [B,3D,3] F, | "Gbm"_G,,3 _G,,/2E,,/2 _G,,2 _D,_G,, | "G"=G,,3 G,,/2E,,/2 G,,2 =B,,[=D,A,,-- ] | "D"[D,3A,,3] D, z4 |
| "Bm" z4 z2 z F,/2=F,/2 | "E"E,,3 E,, E,,2 B,,E,,/2G,,/2- | "G"G,,2- G,,/2G,,E,,/2 G,,3/2B,,/2- B,,2 | "G"_A,/2G,3/2 B,G, "A"=A,2 A,,2 |
| "D" z8 | "Gbm" z8 |
after it has been formatted it is pasted into the Java app Impro-Visor to give the chords.格式化后,将其粘贴到 Java 应用程序 Impro-Visor 中以提供和弦。
Use a global ( g
), multi-line ( m
) RegExp
to match any pipe ( \|
) at the start of a line ( ^
)使用全局 (
g
)、多行 ( m
) 正则RegExp
匹配行首 ( ^
) 的任何 pipe ( \|
)
// here's your original string let tOut = `| D| Gbm| G| A| | D| Gbm| G| A| | Bm| Gbm| G| D| | Bm| Gbm| G| A| | D| Gbm| G| A| | D| Gbm| G| A| | Bm| Gbm| G| D| | Bm| E| G| GA| | D| Gbm|` // replace the pipes tOut = tOut.replace(/^\|?/mg, '') console.log(tOut) // document.write(tOut)
The above also removes the space following the pipe if it's present.如果 pipe 存在,上面的内容也会删除。 If you want to keep the space, change the regex to
/^\|/mg
.如果要保留空间,请将正则表达式更改为
/^\|/mg
。
You can split
the multiline string on the line break ( \n
), use map
to remove the first character from each line, and join
on the line break to convert the array back to a string.您可以在换行符 (
\n
) 上split
多行字符串,使用map
从每行中删除第一个字符,然后join
换行符以将数组转换回字符串。 This works no matter what character each line starts with.无论每行以什么字符开头,这都有效。
const str = `| D| Gbm| G| A| | D| Gbm| G| A| | Bm| Gbm| G| D| | Bm| Gbm| G| A| | D| Gbm| G| A| | D| Gbm| G| A| | Bm| Gbm| G| D| | Bm| E| G| GA| | D| Gbm|`; const res = str.split("\n").map(s=>s.slice(1)).join("\n"); console.log(res);
This is the changed code that worked, prevent line break, remove the ":::|"这是有效的更改代码,防止换行,删除“:::|” and replaced "||"
并替换了“||” with "|"br""
带“|”br“”
tOut += "" //"<br>"
tOut = tOut.split(":::|").join("");
tOut = tOut.split("||").join("|<br>");
document.write(tOut)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.