Click here to Skip to main content
16,016,501 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below we have two file name with .pdf extension. If iam spliting both file name, It gives wrong output.. Any 1 have idea to split a both file using .pdf or any format

i have placed coding and output which came for me. Kindly do the needful.

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
Posted
Comments
Philippe Mori 22-Feb-14 8:57am    
It is not a good idea to split string that way... Each filename should be put inside quotes or in its own line or something similar. That is you should avoid the problem from the beginning.

If you don't have choice,m then the Regex route would be more appropriate as you can validate the pattern and only accept strings that conform to the expected format.

Instead Of String.Split , You can use Regex.Split method

VB
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 = Regex.Split(sscheck, ".pdf,")


Output Will be

VB
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'
 
Share this answer
 
v2
Comments
Philippe Mori 22-Feb-14 8:51am    
You can also use the appropriate overload of split (http://msdn.microsoft.com/fr-fr/library/tabh47cf(v=vs.110).aspx)
String.Split works on single characters, not on a specific string, so when you hand it a string such as ".pdf" VB (being a spectacularly stupid language) casts the string to a character by using just the first character from the string: '.' - a sensible language (such as C#) would have complained that there is no version of Split which takes a string as it's parameter.

You can't break the string on ".pdf" using Split: you need to use a regex, and split on the ',' after the PDF:
VB
Dim regex As New Regex("(?<=\.pdf),")
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"
Dim ssfile As String() = regex.Split(sscheck)
 
Share this answer
 
Comments
Philippe Mori 22-Feb-14 8:50am    
Well, there is an overload that take strings (http://msdn.microsoft.com/fr-fr/library/tabh47cf(v=vs.110).aspx) but you have to specify options...
vinodh107 24-Feb-14 1:10am    
ya thanks you..its working fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900