Code Comments
Programming Forum and web based access to our favorite programming groups."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."
Post Follow-up to this messageOn Thu, 1 Nov 2007 16:40:28 +1300, "Pete Dashwood" <dashwood@removethis.ente rnet.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
Post Follow-up to this message"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."
Post Follow-up to this messageIn 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.