For Programmers: Free Programming Magazines  


Home > Archive > Cobol > November 2007 > Re: Help with Inspect _src_ replacing all [SPACE]ALPHANUMERIC[SPACE] by space









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Help with Inspect _src_ replacing all [SPACE]ALPHANUMERIC[SPACE] by space
Pete Dashwood

2007-11-01, 3:55 am



"Robert" <no@e.mail> wrote in message
news:6c8ii3t6r3qr5uhed8mkts2bnamllk8oj4@
4ax.com...
> On Wed, 31 Oct 2007 12:00:39 -0700, vferr094@alumni.uottawa.ca wrote:
>
>
> You can do it yourself like this:
>
> move 1 to pos-in pos-out
> move spaces to string-out
> perform until pos-in > length of string-in
> move spaces to a-word
> unstring string-in delimited by ALL SPACE
> into a-word with pointer pos-in
> move a-word to temp-word
> inspect temp-word converting
> 'abcdefghijklmnopqrstuvwxyz0123456789' to space
> if temp-word equal to spaces
> move spaces to a-word
> end-if
> string a-word delimited by space
> space
> into string-out with pointer pos-out
> end-perform


An imaginative solution, Robert.

I still prefer:

RegEx.Replace(inputString, @"\s\w+\s", " ") ;

.... which does exactly what the user requested (same as the above), with a
single statement.

The parameters to the "Replace" function are in 3 parts:

1. The input string.
2. The Regular Expression to be matched.
3. The string to replace whatever is matched. (This does NOT have to be the
same length as what is matched; it can be longer or shorter.)

"Translation":
@ = what follows is a "verbatim string"; it doesn't need to have slashes
escaped. This is a C# feature, not part of RegEx.
\s = match a single white space
\w = match a single alphanumeric character (the "w" stands for "word")
+ = there MUST be 1, and CAN be many, of the preceding character.

Lastly, the statement specifies that anything found to match, is to be
replaced by a single space character.

So, ' x ' would match, ' x' would not; ' xxxcv13ed5 ' would match, '
xxxcv$3ed5 ' would not, and so on...

Pete.
--
"I used to write COBOL...now I can do anything."



Robert

2007-11-01, 3:55 am

On Thu, 1 Nov 2007 16:40:28 +1300, "Pete Dashwood" <dashwood@removethis.enternet.co.nz>
wrote:

>
>
>"Robert" <no@e.mail> wrote in message
> news:6c8ii3t6r3qr5uhed8mkts2bnamllk8oj4@
4ax.com...
>
>An imaginative solution, Robert.
>
>I still prefer:
>
>RegEx.Replace(inputString, @"\s\w+\s", " ") ;
>
>... which does exactly what the user requested (same as the above), with a
>single statement.
>
>The parameters to the "Replace" function are in 3 parts:
>
>1. The input string.
>2. The Regular Expression to be matched.
>3. The string to replace whatever is matched. (This does NOT have to be the
>same length as what is matched; it can be longer or shorter.)
>
>"Translation":
>@ = what follows is a "verbatim string"; it doesn't need to have slashes
>escaped. This is a C# feature, not part of RegEx.
>\s = match a single white space
>\w = match a single alphanumeric character (the "w" stands for "word")
>+ = there MUST be 1, and CAN be many, of the preceding character.
>
>Lastly, the statement specifies that anything found to match, is to be
>replaced by a single space character.
>
>So, ' x ' would match, ' x' would not; ' xxxcv13ed5 ' would match, '
>xxxcv$3ed5 ' would not, and so on...


If he had access to Oracle 10, he could use Posix notation, which is easier to read:

SELECT REGEXP_REPLACE
(:string-in,
'[:space:][:alpha:]+[:space:]',
' '
)
INTO :string-out
FROM dual
Pete Dashwood

2007-11-01, 6:55 pm



"Robert" <no@e.mail> wrote in message
news:ukpii39nk01e9c399rttdhguk9o81dnojb@
4ax.com...
> On Thu, 1 Nov 2007 16:40:28 +1300, "Pete Dashwood"
> <dashwood@removethis.enternet.co.nz>
> wrote:
>
>
> If he had access to Oracle 10, he could use Posix notation, which is
> easier to read:
>
> SELECT REGEXP_REPLACE
> (:string-in,
> '[:space:][:alpha:]+[:space:]',
> ' '
> )
> INTO :string-out
> FROM dual


Excellent!

I didn't know you could do that with ORACLE :-)

Pete.
--
"I used to write COBOL...now I can do anything."



2007-11-02, 7:55 am

In article <5ov3diFoodpjU1@mid.individual.net>,
Pete Dashwood <dashwood@removethis.enternet.co.nz> wrote:
>
>
>"Robert" <no@e.mail> wrote in message
> news:ukpii39nk01e9c399rttdhguk9o81dnojb@
4ax.com...


[snip]

>
>Excellent!
>
>I didn't know you could do that with ORACLE :-)


I believe, Mr Dashwood, that one can do such things with Oracle version 10
or higher; I do not recall it being a part of version 9i when I studied
such.

DD

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com