我正在尝试使用两个变量(用户名和密码)读取文件,例如: user1,password1
如何将值分开并存储在不同的变量中?我试过这个,但它似乎不存储字符串本身。
似乎看不到逗号。另一个想法是\M
在每个字符串后使用“,”进行匹配并存储该字符串,但这是行不通的。
感谢一些帮助。
set varuser [lsearch -inline -all $userpass "*,"]
set varuser [regexp {,\s+"(.*)"} $userpass all value]
由于用户的密码可能包含逗号,因此我倾向于使用正则表达式方法:
% set line {user1,my,clever,password}
user1,my,clever,password
% lassign [regexp -inline {^(.+?),(.*)$} $line] -> user pass
% set user
user1
% set pass
my,clever,password
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句