user705414
user705414

Reputation: 21200

How to achieve the find and replace following task?

I have a string pattern like "test" : "abc/gef fhhff/fhrhr krerjr",

I would like to replace all space in the line beginning with "test" with plus sign. How to do that using regular expression?

Upvotes: 2

Views: 89

Answers (2)

Zunair
Zunair

Reputation: 1195

for vb net try

        Dim strCurrentLine as string = "test : abc/gef fhhff/fhrhr krerjr"

        If UCase(strCurrentLine.ToString.StartsWith("TEST")) = True Then
            strCurrentLine = Replace(strCurrentLine.ToString, " ", "Replace space with this text")
        End If

for C# try

    string strCurrentLine = "test : abc/gef fhhff/fhrhr krerjr";

    if (Strings.UCase(strCurrentLine.ToString().StartsWith("TEST")) == true) {
        strCurrentLine = Strings.Replace(strCurrentLine.ToString(), " ", "Replace space with this text");
    }

or go here for vb regex http://visualbasic.about.com/od/usingvbnet/a/RegExNET_2.htm

or go here for c# regex http://oreilly.com/windows/archive/csharp-regular-expressions.html

Upvotes: 1

Tudor Constantin
Tudor Constantin

Reputation: 26861

In perl you have to do something like:

use strict;
use warnings;

use 5.010;

my $text = q|test : "abc/gef fhhff/fhrhr krerjr"|;

#below is the regex that does the replace - \s is for whitespace class
$text =~ s/\s/+/gmix if ( $text =~ /^test/gmix);

say "new text: $text";

Upvotes: 0

Related Questions