使用扩展名的文件名拆分选项 [英] split option using filename with extension
问题描述
下面我们有两个文件名,扩展名为.pdf。如果iam拆分两个文件名,它会给出错误的输出..任何1都有想法使用.pdf或任何格式拆分两个文件
i已经放置了编码和输出来找我。请做必要的。
dim ssfile()as string Dim sscheck As String = Your Weekend(Supp。to Press and Journal,Aberdeen)_20140205_004.pdf,Your Weekend (补充到Press and Journal,Aberdeen)_11111111_004.pdf
ssfile = sscheck .Split(。pdf,)
输出我得到如下:
ssfile(1)='你的周末(补充'
ssfile( 2)='按Press and Journal,Aberdeen)_20140205_004'
ssfile(3)='pdf,你的周末(补充'
ssfile(4)='按和期刊,Aberdeen)_11111111_004'
ssfile(5)='pdf'
但我需要一个输出:
ssfile(1)='你的周末(补充新闻和日记,Aberdeen)_20140205_004.pdf'
ssfile(2)='你的周末(补充到Press and Journal,Aberdeen)_11111111_004.pdf'
谢谢你
String.Split,你可以使用正则表达式.Split方法
Dim ssfile() As String
Dim sscheck As String = 你的周末(补充。 to Press and Journal,Aberdeen)_20140205_004.pdf,Your Weekend(Supp。to Press and Journal,Aberdeen)_11111111_004.pdf
ssfile = Regex.Split(sscheck, 。pdf,)
输出
ssfile( 1 )= ' 您的周末(补充新闻和期刊,Aberdeen)_20140205_004.pdf'
ssfile( 2 )= ' 您的周末(Supp 。到Press and Journal,Aberdeen)_11111111_004.pdf'
String.Split适用于单个字符,而不是特定的字符串,所以当你把它交给一个像.pdf的字符串VB(是一种非常愚蠢的语言)通过使用字符串中的第一个字符来将字符串转换为字符:'。' - 一种合理的语言(比如C#)会抱怨没有Split的版本,它接受一个字符串作为参数。
你不能破坏.pdf上的字符串使用Split:您需要使用正则表达式,并在PDF之后拆分',':
Dim regex 作为 新正则表达式( (?< = \.pdf),)
Dim sscheck 作为 字符串 = 你的周末(补充。 to Press and Journal,Aberdeen)_20140205_004.pdf,Your Weekend(Supp.to Press and Journal,Aberdeen)_11111111_004.pdf
Dim ssfile 作为 字符串()= regex.Split(sscheck)
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
Instead Of String.Split , You can use Regex.Split method
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
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'
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:
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)
这篇关于使用扩展名的文件名拆分选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!