|
-
Oct 15th, 2010, 01:06 AM
#1
Thread Starter
Hyperactive Member
-
Oct 15th, 2010, 02:04 AM
#2
Re: String.Split with Enters and Tabs
Try this:
Code:
strClipText = _
iData.GetData(DataFormats.Text, True).ToString().Split(New String() _
{Environment.NewLine, ControlChars.Tab}, _
StringSplitOptions.None)
-
Oct 15th, 2010, 02:31 AM
#3
Thread Starter
Hyperactive Member
Re: String.Split with Enters and Tabs
VB.NET 2003 doesn't seem to like StringSplitOptions.None
-
Oct 15th, 2010, 02:37 AM
#4
Re: String.Split with Enters and Tabs
My fault, didn't look at the version.
The problem is that Environment.NewLine is actually a String having CR (0xD) and LF (0xA) characters.
You need a string as a separator, otherwise Split function will try to separate CRs and LFs.
Create a string array, not char.
Code:
Dim Separators(1) As String
Separators(0) = Environment.NewLine
Separators(1) = ControlChars.Tab
iData.GetData(DataFormats.Text, True).ToString().Split(Separators)
-
Oct 15th, 2010, 03:03 AM
#5
Thread Starter
Hyperactive Member
Re: String.Split with Enters and Tabs
Cool. Thanks! 
I've implemented it like this :
Code:
If iData.GetDataPresent(DataFormats.Text) Then
strClipText = iData.GetData(DataFormats.Text, True).ToString().Split(Separators(0))
strClipText2 = iData.GetData(DataFormats.Text, True).ToString().Split(Separators(1))
End If
Last question, hopefully.
Seeing the fact that I have only one array here containing everything. Is there a way to disregard the empty elements? Meaning that every second item now is empty, how can I determine that?
-
Oct 15th, 2010, 03:06 AM
#6
Re: String.Split with Enters and Tabs
Well, in some later versions of the Framework there is StringSplitOptions.RemoveEmptyEntries option, but here you should do it manually by checking each element of the resulting array and removing it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|