Elisp分割字符串函数,用于将字符串分割。字符 [英] Elisp split-string function to split a string by . character

查看:155
本文介绍了Elisp分割字符串函数,用于将字符串分割。字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用基于的分割字符串功能分割字符串。字符。但是
(分割字符串 1.2.3。)根本不起作用。它只返回可变数目的空字符串的列表。是。

I am trying to split a string using 'split-string' function based on the . character. But (split-string "1.2.3" ".") doesn't work at all. It just returns a list of variable number of empty strings. Is . a special character that needs to be escaped or specified in some different way?

推荐答案

以下是拆分字符串功能的官方文档- http://www.gnu.org/software/emacs/manual/html_mono /elisp.html#Creating-Strings

Here is the official documentation for split-string function - http://www.gnu.org/software/emacs/manual/html_mono/elisp.html#Creating-Strings.

中的分割字符串函数的第二个参数(分割字符串 1.2.3 \。)是一个正则表达式,因此。字符和 \字符都具有特殊含义。因此,'。'字符需要转义,甚至'\'字符也需要与另一个'\'转义。 (分割字符串 1.2.3 \\。)可以按预期工作。

The second argument to the split-string function in (split-string "1.2.3" "\.") is a regular expression and as a result both the '.' character and '\' character have special meaning. So the '.' character needs to be escaped and even the '\' character needs to be escaped with another '\'. (split-string "1.2.3" "\\.") will work fine as expected.

这篇关于Elisp分割字符串函数,用于将字符串分割。字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆