我有一个字符串变量str,它保存的值是
来自 HTML texarea
我正在尝试用新行分割字符串
fmt.Println("befor split:")
fmt.Println(str)
x := strings.Split(str, "\n")
fmt.Println("after split:")
fmt.Println(x)
这就是我得到的
不同类型的行结束符:根据平台的不同,换行符可以表示为 (视窗), (Unix/Linux),或 (老麦克)。
const textareaValue = document.getElementById("yourTextareaId").value;
const lines = textareaValue.split(/\r?\n/); // This will handle both \r\n and \n