Mitteg
Mitteg

Reputation: 169

How to delete repeated specific characters

I need to replace the "@" with "-" in a string. This is straightforward, but I also need to replace multiple "@@@@@" with just one single "-". Any ideas on how to do the latter with ASP. Here is an example:

input string: @Introducción a los Esquemas Algorítmicos: Apuntes y colección de problemas. Report LSI-97-6-T@@@@@@@@09/30/1997@@@@@TRE@

Desired output: -Introducción a los Esquemas Algorítmicos: Apuntes y colección de problemas. Report LSI-97-6-T-09/30/1997-TRE-

Thanks.

Upvotes: 0

Views: 31

Answers (2)

DNKROZ
DNKROZ

Reputation: 2852

Try this for classic ASP:

Dim regEx
Set regEx = New RegExp

 With regEx
    .Pattern = "([\@])\1+|(\@)"
    .Global = True
    .MultiLine = True
End With
strMessage = regEx.Replace(str, "-")

This will match every occurrence of multiple @@@@ or single occurrences of @

Not sure what language you are using so here's the expression in full with delimiters: /([\@])\1+|(\@)/g

Edit - Even simpler: /@+/g

enter image description here

Upvotes: 1

msaint
msaint

Reputation: 101

    using System;
    using System.Text.RegularExpressions;

    public class Program
    {
        public static void Main()
        {
            Console.WriteLine("Hello World");
            String input = "@Introducción a los Esquemas Algorítmicos: Apuntes y colección de problemas. Report LSI-97-6-T@@@@@@@@09/30/1997@@@@@TRE@";
            String output=Regex.Replace(input,@"\@+","-");
            Console.WriteLine(output);

        }
    }

Upvotes: 0

Related Questions