Click here to Skip to main content
15,744,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a string whose part is always changing, and I want to remove that part from the string like this:

Our society, 01:12:15:14 the whole country
Our society, the whole country

This format should be removed from the string: 01:12:15:14
This format is always changing and cannot be deleted with the replace command like this:

joins our 02:00:47:13 struggle.
We 02:01:29:03 begin our gathering

How can I do this?

What I have tried:

I have no idea how to do this.
Updated 13-Mar-23 21:32pm

one way of doing it:
Dim message = "Our society, 01:12:15:14 the whole country"
Dim result(message.Length) As Char
Dim position As Integer = 0

For i As Integer = 0 To message.Length - 1

    If "1234567890:".Contains(message(i)) Then
        Continue For
    End If

    result(position) = message(i)
    position += 1


Dim newMessage = New String(result).Trim(vbNullChar)
Share this answer
CPallini 14-Mar-23 9:10am    
Use a Regex:
Imports System.Text.RegularExpressions

'  Regular expression built for Visual Basic on: Tue, Mar 14, 2023, 07:29:32 AM
'  Using Expresso Version: 3.0.4750,
'  A description of the regular expression:
'  \s\d+:\d+:\d+:\d+\s
'      Whitespace
'      Any digit, one or more repetitions
'      :
'      Any digit, one or more repetitions
'      :
'      Any digit, one or more repetitions
'      :
'      Any digit, one or more repetitions
'      Whitespace

Public Dim regex As Regex = New Regex( _
      "\s\d+:\d+:\d+:\d+\s", _
    RegexOptions.IgnoreCase _
    Or RegexOptions.Multiline _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.IgnorePatternWhitespace _
    Or RegexOptions.Compiled _
public Dim regexReplace As String = " "
    Dim result As String = regex.Replace(InputText,regexReplace)

If you are going to use regular expressions, you need a helper tool. Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
Share this answer
Graeme_Grant 14-Mar-23 3:49am    
He's struggling with basic coding, RegEx will sink him!
OriginalGriff 14-Mar-23 4:49am    
Time for some education! :D
Graeme_Grant 14-Mar-23 5:06am    
CPallini 14-Mar-23 9:11am    
Member 12617947 14-Mar-23 14:25pm    
@OriginalGriff Dear OriginalGriff,Thank you for your help. This is a great solution because it does not delete a number in String and Only numbers with a specific format are removed

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