我有一個像後續的字符串:分割字符串使用掃描儀或正則表達式的Java
AddStudent,addingToListAddStudent,FD,M,fdsq,fdsq,85/26/9541,fdsq,842-568 523,fdqs,fdqs,fdsq,fdsq,4,MAT101,Math 101,Mr. Smith,20,3.15,1,Computer Science Bsc,120
(全部在一行中)
我想擺脫「AddStuent,addingToListAddStudent」的。我的問題是,字符串可能會有所不同。我可以有更多元素用逗號分隔。我看着使用reuglare表達式,但我無法得到它的工作。我厭倦了使用正則表達式,但我不知道如何使用它:
/([^,]+)/
解決方案
我用湯姆的回答簡單,快速,乾淨,因爲我的弦總是要有相同的2個第一個元素。所以我用這個:
string.replace("AddStudent,addingToListAddStudent,", "");
這樣做最常規的方法是什麼?使用字符串替換或正則表達式?
將「AddStudent,addingToListAddStudent」總是在字符串的開始? – 2014-12-03 14:24:05
'string.replace(「AddStudent,addingToListAddStudent,」,「」);'? – Tom 2014-12-03 14:26:39
是的,它會永遠是,它是一個「命令」,我發送到服務器 – Tuytuy 2014-12-03 14:26:51