Reputation: 65
Below we have two file name with .pdf
extension. If I am splitting both file names, it gives wrong output. Any one have an idea on how to split both files using .pdf
or any format?
I have placed code and the output I get.
dim ssfile() as string
Dim sscheck As String="Your Weekend (Supp. to Press and Journal, Aberdeen)_20140205_004.pdf,Your Weekend (Supp. to Press and Journal, Aberdeen) _11111111_004.pdf"
ssfile= sscheck .Split(".pdf,")
Output which I got follows:
ssfile(1)='Your Weekend (Supp'
ssfile(2)='to Press and Journal, Aberdeen)_20140205_004'
ssfile(3)='pdf,Your Weekend (Supp'
ssfile(4)='to Press and Journal, Aberdeen) _11111111_004'
ssfile(5)='pdf'
but I need an ouput as:
ssfile(1)='Your Weekend (Supp. to Press and Journal, Aberdeen)_20140205_004.pdf'
ssfile(2)='Your Weekend (Supp. to Press and Journal, Aberdeen) _11111111_004.pdf'
thank you
Upvotes: 0
Views: 648
Reputation: 137
if (args[0] != null) {
String path = System.getProperty("user.dir");
String fileName = args[0];
String nameOfFile[] = fileName.split("\\.(?=[^\\.]+$)");
if (nameOfFile[1].equals("docx"))
new DocToXmlConverter().processDocxToXml(path, nameOfFile[0]);
else if (nameOfFile[1].equals("doc"))
new DocToXmlConverter().processDocToXml(path, nameOfFile[0]);
else
throw new Exception("please provide Correct File Extension");
}
Upvotes: 0
Reputation: 216303
You need to set the correct overload of string.Split
ssfile= sscheck.Split(new string() {".pdf,"}, StringSplitOptions.RemoveEmptyEntries)
but afterwards, the first file loose its extension so you need to readd it
ssFile(0) = ssFile(0) & ".pdf"
By the way, your actual result seems to be the effect of having Option Strict set to Off in your project. This allows the implicit conversion of the first character of your string to a single char and thus the selection of the wrong Split overload (the one that takes just a single char).
I really suggest to change Option Strict to On for your project even if at first attempt you have many error to fix.
Upvotes: 1