Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
INPUT
2015-04-22 JV RM - Save your list here 2014-12-28 SV See Word - Image in the mail2014-12-21 SV See word document02014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here

I neeed to split this as
2015-04-22 JV RM - Save your list here
2014-12-28 SV See Word - Image in the mail
2014-12-21 SV See word document0
2014-12-15 SV See word
2014-11-09 SV First small items to start programming here. See the pdf in attach
2014-11-09 SV First small items to start programming here. See the pdf in attach-
2014-11-09 SV First small items to start programming here. See the pdf in attach
2014-11-09 SV First small items to start programming here. See the pdf in attach-
2014-12-15 SV See word
2014-11-09 SV First small items to start programming here. See the pdf in attach
2014-11-09 SV First small items to start programming here

Like this I need
VB
    Private Sub Cmd_Rem_Click(sender As Object, e As EventArgs) Handles Cmd_Rem.Click
        Dim input As String = Txt_Commantaarintern.Text
       Dim result As String() = Regex.Split(input, "(?<=['""A-Za-z0-9][\.\!\?])\s+(?=[A-Z])")
            For Each s As String In result
            Console.WriteLine(s)
Txt_After_Remove .Text =s 
        Next

    End Sub

Please Guide me Where i Stuck
Posted

Regex.Split probably isn't going to help you much: it removes the match code and discards it. Since your "new line" data contains info you want to keep, that's a problem.
I'd use a regex like this:
\d{4}-\d\d-\d\d
and then use the https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.capture.index(v=vs.110).aspx property to tell me where each line starts.
I could then split out each individual line using string.Substring
 
Share this answer
 
Comments
Bensingh 28-May-15 2:08am    
On using this the date get deleted
OriginalGriff 28-May-15 2:19am    
Read the words as well... :sigh:
In addition to OriginalGriff[^] answer, here is an implementation of His words ;)


C#
string s = @"2015-04-22 JV RM - Save your list here 2014-12-28 SV See Word - Image in the mail2014-12-21 SV See word document02014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here";

System.Text.RegularExpressions.Regex searchTerm =
  new System.Text.RegularExpressions.Regex(@"(\d{4}-\d{2}-\d{2})");
			
var matches = from System.Text.RegularExpressions.Match match in searchTerm.Matches(s)
                                select new{match.Value, match.Index};
//see result #1

var matchedValues = matches.Select((Record,RowNo)=>new
			{
				Index = RowNo++,
				Date = Record.Value,
				GetTextFrom = Record.Index,
				GetTextLength = matches.Skip(RowNo++).Take(1).Select(a=>a.Index - Record.Index).FirstOrDefault()
			});
//see Result #2;

List<string> lines = new List<string>();
foreach(var line in matchedValues)
{
	lines.Add(s.Substring(line.GetTextFrom, line.GetTextLength==0 ? s.Length - line.GetTextFrom : line.GetTextLength));
}
//see result #3</string></string>


VB
Dim s As String = "2015-04-22 JV RM - Save your list here 2014-12-28 SV See Word - Image in the mail2014-12-21 SV See word document02014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here"

Dim searchTerm As New System.Text.RegularExpressions.Regex("(\d{4}-\d{2}-\d{2})")

Dim matches = From match In searchTerm.Matches(s) Select New With { _
	match.Value, _
	match.Index _
}

Dim matchedValues = matches.[Select](Function(Record, RowNo) New With { _
	Key .Index = System.Math.Max(System.Threading.Interlocked.Increment(RowNo),RowNo - 1), _
	Key .[Date] = Record.Value, _
	Key .GetTextFrom = Record.Index, _
	Key .GetTextLength = matches.Skip(System.Math.Max(System.Threading.Interlocked.Increment(RowNo),RowNo - 1)).Take(1).[Select](Function(a) a.Index - Record.Index).FirstOrDefault() _
})

Dim lines As New List(Of String)()
For Each line In matchedValues
	lines.Add(s.Substring(line.GetTextFrom, If(line.GetTextLength = 0, s.Length - line.GetTextFrom, line.GetTextLength)))
Next


Result #1 (matches)
Value      Index
2015-04-22 0 
2014-12-28 39 
2014-12-21 81 
2014-12-15 113 
2014-11-09 135 
2014-11-09 215 
2014-11-09 296 
2014-11-09 376 
2014-12-15 457 
2014-11-09 479 
2014-11-09 559


Result #2 (matchedValues)
Index Date       GetTextFrom GetTextLength
0     2015-04-22 0           39 
1     2014-12-28 39          42 
2     2014-12-21 81          32 
3     2014-12-15 113         22 
4     2014-11-09 135         80 
5     2014-11-09 215         81 
6     2014-11-09 296         80 
7     2014-11-09 376         81 
8     2014-12-15 457         22 
9     2014-11-09 479         80 
10    2014-11-09 559         0


Result #3 (lines)
2015-04-22 JV RM - Save your list here  
2014-12-28 SV See Word - Image in the mail 
2014-12-21 SV See word document0 
2014-12-15 SV See word 
2014-11-09 SV First small items to start programming here. See the pdf in attach 
2014-11-09 SV First small items to start programming here. See the pdf in attach- 
2014-11-09 SV First small items to start programming here. See the pdf in attach 
2014-11-09 SV First small items to start programming here. See the pdf in attach- 
2014-12-15 SV See word 
2014-11-09 SV First small items to start programming here. See the pdf in attach 
2014-11-09 SV First small items to start programming here 


[EDIT]
Ooopppsss... :omg:
I missed that question is taged as VB.NET. I'll improve my answer later ;)

Done (VB.NET code has been added)!
 
Share this answer
 
v4
Comments
Bensingh 28-May-15 4:50am    
Thanks a lot
Maciej Los 28-May-15 4:51am    
You're very welcome ;)
Bensingh 9-Jun-15 2:55am    
los another one help need output as

2015-04-22 JV RM - Save your list here
2015-01-04 SV I have placed my last version on your computer. If possible start from there
2014-12-28 SV See Word - Image in the mail
2014-12-21 SV See word document0
2014-12-15 SV See word
2014-11-09 SV First small items to start programming here. See the pdf in attach

is it possible
Maciej Los 9-Jun-15 3:45am    
??? I do not see any changes. Could you be more specific?
Bensingh 9-Jun-15 4:17am    
from our Result #3 (lines)
we need only these
2015-04-22 JV RM - Save your list here
2015-01-04 SV I have placed my last version on your computer. If possible start from there
2014-12-28 SV See Word - Image in the mail
2014-12-21 SV See word document0
2014-12-15 SV See word
2014-11-09 SV First small items to start programming here. See the pdf in attach

As per OP's comments to the soultion 1
VB
Sub Main
	Dim s As String = "2015-04-22 JV RM - Save your list here 2014-12-28 SV See Word - Image in the mail2014-12-21 SV See word document02014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here"
	 
	Dim searchTerm As New System.Text.RegularExpressions.Regex("(\d{4}-\d{2}-\d{2})")
	 
	Dim matches = From match In searchTerm.Matches(s) Select New With { _
		match.Value, _
		match.Index _
	}
	 
	Dim matchedValues = From m In matches _
		Let RowNo  = increment _
		Select New With { _
			Key .Index = RowNo, _
			Key .[Date] = m.Value, _
			Key .GetTextFrom = m.Index, _
			Key .GetTextLength = matches.Skip(RowNo).Take(1).[Select](Function(a) a.Index - m.Index).FirstOrDefault() _
		}
	
	Dim lines As New List(Of MyMessage)()
	For Each line In matchedValues
		Dim sDate as String = s.Substring(line.GetTextFrom, 10)
		'Console.WriteLine("{0} - {1}", line.GetTextFrom, If(line.GetTextLength Is Nothing, s.Length - line.GetTextFrom, line.GetTextLength)-10)
		Dim sMsg as String = s.Substring(line.GetTextFrom+10, If(line.GetTextLength Is Nothing, s.Length - line.GetTextFrom, line.GetTextLength)-10).Replace("-","").Trim()
		Dim oMsg = New MyMessage(sDate, sMsg)
		If Not lines.Contains(oMsg) Then lines.Add(oMsg)
	Next
	
End Sub

' Define other methods and classes here

Public Shared Function increment() As Integer
     Static i As Integer
     i = i + 1
     Return i
End Function


Public Class MyMessage 
	Implements IEquatable(Of MyMessage)

	Dim sDate As String = String.Empty
	Dim sMessage As String = String.Empty
	
	Public Sub New(_Date as String, _Message As String)
		sDate = _Date
		sMessage = _Message
	End Sub
	
	Public Property aDate As String
		Get
			Return sDate
		End Get
		Set (value As String)
			sDate = value
		End Set
	End Property

	Public Property aMessage As String
		Get
			Return sMessage
		End Get
		Set (value As String)
			sMessage = value
		End Set
	End Property
	
    Public Overrides Function Equals(obj As Object) As Boolean 
        If obj Is Nothing Then 
            Return False 
        End If 
        Dim objMyMessage As MyMessage = TryCast(obj, MyMessage)
        If objMyMessage Is Nothing Then 
            Return False 
        Else 
            Return Equals(objMyMessage)
        End If 
    End Function 
    Public Overrides Function GetHashCode() As Integer 
        Return aMessage
    End Function 
    Public Overloads Function Equals(other As MyMessage) As Boolean _
        Implements IEquatable(Of MyMessage).Equals
        If other Is Nothing Then 
            Return False 
        End If 
        Return (Me.aMessage.Equals(other.aMessage))
    End Function 

End Class


Result:
aDate       aMessage
2015-04-22 JV RM  Save your list here 
2014-12-28 SV See Word  Image in the mail 
2014-12-21 SV See word document0 
2014-12-15 SV See word 
2014-11-09 SV First small items to start programming here. See the pdf in attach 
2014-11-09 SV First small items to start programming here 
 
Share this answer
 
Comments
Bensingh 9-Jun-15 9:57am    
How to display the output in a textbox value on button click
Maciej Los 9-Jun-15 12:59pm    
Do not use TextBox. Use DataGridView instead. For example:
DataGridView1.DataSource = lines.ToList()
Bensingh 9-Jun-15 23:59pm    
I need to display it in the text box value as

2015-04-22 JV RM Save your list here
2014-12-28 SV See Word Image in the mail
2014-12-21 SV See word document0
2014-12-15 SV See word
2014-11-09 SV First small items to start programming here. See the pdf in attach
2014-11-09 SV First small items to start programming here

No need of headings aDate aMessage.
Is it possible
Maciej Los 10-Jun-15 2:10am    
You have to add method to the class definition:
Public Overrides Function ToString() As String
Return String.Format("{0} {1}", sDate, sMessage)
End Function

Now, add below code after last loop For Each line in matchedValues ... Next
Dim sb = New StringBuilder()
For Each msg in lines
sb.AppendLine(msg.ToString())
Next
TextBox1.Multiline = true
TextBox1.Text = sb.ToString()


Note: i do not recommend to display such of data in TextBox!!!
Maciej Los 10-Jun-15 2:15am    
By The Way...
Please, stop doing this! Stop asking me for help. You have to do - at least - minimum effort...
Cheers, Maciej

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