Jump to content

replace a character i specific modes !


Recommended Posts

hello everybody  

first I read many examples but nothing help!

I have this string:

Quote

Company name: galaxy-1
Address: 1st. sq, - build 1
Tel: 011-2333 - 055-2213
Fax: 033-11124423

all I need is to delete "-" which is included in numbers only! so I need this result:

Quote

Company name: galaxy-1
Address: 1st. sq, - build 1
Tel: 0112333 - 0552213 
Fax: 03311124423

If I used StringReplace function it replace all "-", not as above 

please help 

 

Link to comment
Share on other sites

Here's one of many ways that it can be done:

Example()
Func Example()
    Local $sBefore = _
        "Company name: galaxy-1" & @CRLF & _
        "Address: 1st. sq, - build 1" & @CRLF & _
        "Tel: 011-2333 - 055-2213" & @CRLF & _
        "Fax: 033-11124423" & @CRLF
    Local $sAfter = StringRegExpReplace($sBefore, "\b(\d+)-(\d+)\b", "\1\2")

    ConsoleWrite("Before:" & @CRLF & $sBefore)
    ConsoleWrite(@CRLF)
    ConsoleWrite("After:" & @CRLF & $sAfter)
EndFunc

Output:

Before:
Company name: galaxy-1
Address: 1st. sq, - build 1
Tel: 011-2333 - 055-2213
Fax: 033-11124423

After:
Company name: galaxy-1
Address: 1st. sq, - build 1
Tel: 0112333 - 0552213
Fax: 03311124423

 

Edited by TheXman
Link to comment
Share on other sites

3 hours ago, TheXman said:

Here's one of many ways that it can be done:

Example()
Func Example()
    Local $sBefore = _
        "Company name: galaxy-1" & @CRLF & _
        "Address: 1st. sq, - build 1" & @CRLF & _
        "Tel: 011-2333 - 055-2213" & @CRLF & _
        "Fax: 033-11124423" & @CRLF
    Local $sAfter = StringRegExpReplace($sBefore, "\b(\d+)-(\d+)\b", "\1\2")

    ConsoleWrite("Before:" & @CRLF & $sBefore)
    ConsoleWrite(@CRLF)
    ConsoleWrite("After:" & @CRLF & $sAfter)
EndFunc

Output:

Before:
Company name: galaxy-1
Address: 1st. sq, - build 1
Tel: 011-2333 - 055-2213
Fax: 033-11124423

After:
Company name: galaxy-1
Address: 1st. sq, - build 1
Tel: 0112333 - 0552213
Fax: 03311124423

 

it works fine thaaaanks so much :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...