The following method will leave an empty item in the result:
Select[stringLines, Not@*StringStartsQ["#"]]
As shown below:
In[112]:= (*If you actually want the individual lines,*)
stringLines = Import[file, {"Text", "Lines"}];
(*You could use Select:
*)
Select[stringLines, Not@*StringStartsQ["#"]][[1;;5]]
Out[113]= {"", "x,y,z", "x,y+1/8,z+7/8", "x,y+1/4,z+3/4", \
"x,y+3/8,z+5/8"}
I tried the following method, but it could not achieve the purpose of removing the above empty item:
Select[stringLines, Not@*StringStartsQ["#"]&& #=!=""&]
In fact, the above code will give you the following strange result:
{}
What's even stranger is that I tried the different methods below, and their results were different:
In[249]:= Select[stringLines, Not@*StringStartsQ["#"]]//DeleteCases[#, ""]&;
%===Select[stringLines, Not@*StringStartsQ["#"]]/. "" -> Nothing
Out[250]= False
But the check below confirms that they are exactly the same:
In[278]:= listA=Select[stringLines, Not@*StringStartsQ["#"]]//DeleteCases[#, ""]&;
listB=Select[stringLines, Not@*StringStartsQ["#"]]/. "" -> Nothing;
ForAll[MapThread[SameQ, {listA, listB}],True]
Out[280]= True
I've attached the testing file here for your information.
Regards,
Zhao
Attachments: