hi,
I want help in developing the following code.

step1 : match Todays date with string in Paragraph.
Step 2: if Date matches, extract from Date to EndOfLine.

Step 1 code

If InStr(status_array(i), Format(Now(), "mm-dd-yyyy")) <> 0 Then
Step2 code

End If

Please help me developing code for Step2.

Regards,
Dinil

Dani AI

Generated

: the goal is simply to find today's date in the text and return everything from that date to the end of the line. and demonstrate the classic "find the index then take the substring" approach, which is fine for single-line strings with a fixed, exact date format.

If the input can contain multiple lines, variable spacing, or different date formats, a more robust approach is to match the date with a regular expression and capture only the remainder of the same line. This avoids grabbing text from following lines and handles punctuation around the date. Also confirm whether you are on VB.NET or VB6/VBA (format token rules differ and VB.NET favors DateTime.ToString).

Example (VB.NET) pattern idea: match the exact formatted date and capture everything up to but not including the next newline.

Dim dateStr As String = DateTime.Now.ToString("MM-dd-yyyy")
Dim pattern As String = "\b" & Regex.Escape(dateStr) & "\b([^\r\n]*)"
Dim m As Match = Regex.Match(status_array(i), pattern)
If m.Success Then
    Dim tail As String = m.Groups(1).Value.Trim()
End If

Notes: use Regex.Escape when inserting a generated date string, trim the result, use Regex.Matches to handle multiple occurrences, and prefer an unambiguous date format (e.g., yyyy-MM-dd) or explicit CultureInfo when generating the date string for matching. For VB6/VBA, apply the same pattern idea with VBScript.RegExp.

Recommended Answers

All 2 Replies

Dim iLoc as Integer
Dim tStr as Integer
iLoc = 0

iLoc = InStr(1, status_array(i), Format(Now(), "mm-dd-yyyy"))
tStr = ""
If  iLoc <> 0 Then
    tStr = Mid(status_array(i), iLoc, Len(status_array(i)) - (iLoc - 1))
    'tStr now holds the string extracte from Date to EndOfLine

'    If you want to omit the date then use this
'    tStr = Mid(status_array(i), iLoc+10, Len(status_array(i)) - (iLoc - 11))

End If

Hi,

Try This :

Dim j As Integer
Dim NewStr As String
j = InStr(status_array(i), Format(Now(), "mm-dd-yyyy"))
If j <> 0 Then
    NewStr = Mid(status_array(i), j)
End If

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.