Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #11493 > unrolled thread

How to economically(!) remove a range of unknown(!) characters from a string

Started by"R.Wieser" <address@not.available>
First post2017-01-03 13:40 +0100
Last post2017-01-03 17:39 +0100
Articles 18 on this page of 38 — 5 participants

Back to article view | Back to microsoft.public.scripting.vbscript


Contents

  How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-03 13:40 +0100
    Re: How to economically(!) remove a range of unknown(!) characters from a string "Mayayana" <mayayana@invalid.nospam> - 2017-01-03 08:43 -0500
      Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-03 17:21 +0100
        Re: How to economically(!) remove a range of unknown(!) characters from a string "Mayayana" <mayayana@invalid.nospam> - 2017-01-03 19:33 -0500
          Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-04 10:36 +0100
            Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-04 12:21 +0100
              Re: How to economically(!) remove a range of unknown(!) characters from a string "Mayayana" <mayayana@invalid.nospam> - 2017-01-04 08:31 -0500
                Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-04 17:27 +0100
                  Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-04 18:13 +0100
                    Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-04 21:53 +0100
                      Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-05 00:33 +0100
                        Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-05 09:19 +0100
                          Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-05 10:10 +0100
                            Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-05 10:34 +0100
                            Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-05 11:50 +0100
                      Re: How to economically(!) remove a range of unknown(!) characters from a string "Mayayana" <mayayana@invalid.nospam> - 2017-01-05 09:44 -0500
                        Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-05 16:50 +0100
                          Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-05 17:29 +0100
                          Re: How to economically(!) remove a range of unknown(!) characters from a string "Mayayana" <mayayana@invalid.nospam> - 2017-01-05 11:50 -0500
                    Re: How to economically(!) remove a range of unknown(!) characters from a string "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2017-01-04 22:57 -0500
                      Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-05 09:54 +0100
                        Re: How to economically(!) remove a range of unknown(!) characters from a string "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2017-01-05 04:51 -0500
                          Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-05 12:17 +0100
                      Re: How to economically(!) remove a range of unknown(!) characters from a string "Mayayana" <mayayana@invalid.nospam> - 2017-01-05 09:38 -0500
                        Re: How to economically(!) remove a range of unknown(!) characters from a string "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2017-01-05 13:11 -0500
                          Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-05 22:42 +0100
                            Re: How to economically(!) remove a range of unknown(!) characters from a string "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2017-01-05 17:35 -0500
                              Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-06 00:46 +0100
                                Re: How to economically(!) remove a range of unknown(!) characters from a string "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2017-01-05 21:03 -0500
                          Re: How to economically(!) remove a range of unknown(!) characters from a string "Mayayana" <mayayana@invalid.nospam> - 2017-01-05 18:41 -0500
    Re: How to economically(!) remove a range of unknown(!) characters from a string Ulrich Möller <knobbi38@arcor.de> - 2017-01-03 15:03 +0100
      Re: How to economically(!) remove a range of unknown(!) characters from a string Ulrich Möller <knobbi38@arcor.de> - 2017-01-03 15:26 +0100
        Re: How to economically(!) remove a range of unknown(!) charactersfrom a string "R.Wieser" <address@not.available> - 2017-01-03 17:33 +0100
      Re: How to economically(!) remove a range of unknown(!) charactersfrom a string "R.Wieser" <address@not.available> - 2017-01-03 17:26 +0100
    Re: How to economically(!) remove a range of unknown(!) characters from a string "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-03 15:06 +0100
      Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-03 17:29 +0100
    Re: How to economically(!) remove a range of unknown(!) characters from a string "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2017-01-03 11:17 -0500
      Re: How to economically(!) remove a range of unknown(!) characters from a string "R.Wieser" <address@not.available> - 2017-01-03 17:39 +0100

Page 2 of 2 — ← Prev page 1 [2]


#11519

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-01-05 09:54 +0100
Message-ID<XnsA6F464B60F6A1eejj99@194.109.6.166>
In reply to#11517
"Dave \"Crash\" Dummy" <invalid@invalid.invalid> wrote on 05 Jan 2017 in
microsoft.public.scripting.vbscript: 

> Evertjan. wrote:
>> It is a pity that VBS has only the mid() function and has lost the
>> mid() statement found in earlier forms of Basic, because there the
>> swap-function would have looked like:
> 
>> temp = mid(txt,n1,1)
>> mid(txt,n1,1) = mid(txt,n2,1)
>> mid(txt,n2,1) = temp
> 
> You can still come close:
> 
> temp1=mid(txt,n1,1)
> temp2=mid(txt,n2,1)
> txt=left(txt,n1-1) & temp2 & mid(txt,n1+1)
> txt=left(txt,n2-1) & temp1 & mid(txt,n2+1)

Not that simple, 
as when n1 or n2 is 1,
you will get an error.

left(txt,0) 
should, imho, return "", 
but it fails to do that in VBS.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#11522

From"Dave \"Crash\" Dummy" <invalid@invalid.invalid>
Date2017-01-05 04:51 -0500
Message-ID<o4l4s4$q9n$1@dont-email.me>
In reply to#11519
Evertjan. wrote:
> "Dave \"Crash\" Dummy" <invalid@invalid.invalid> wrote on 05 Jan 2017 in
> microsoft.public.scripting.vbscript: 
> 
>> Evertjan. wrote:
>>> It is a pity that VBS has only the mid() function and has lost the
>>> mid() statement found in earlier forms of Basic, because there the
>>> swap-function would have looked like:
>>> temp = mid(txt,n1,1)
>>> mid(txt,n1,1) = mid(txt,n2,1)
>>> mid(txt,n2,1) = temp
>> You can still come close:
>>
>> temp1=mid(txt,n1,1)
>> temp2=mid(txt,n2,1)
>> txt=left(txt,n1-1) & temp2 & mid(txt,n1+1)
>> txt=left(txt,n2-1) & temp1 & mid(txt,n2+1)
> 
> Not that simple, 
> as when n1 or n2 is 1,
> you will get an error.
> 
> left(txt,0) 
> should, imho, return "", 
> but it fails to do that in VBS.

I don't get an error. I get a zero length string for left(txt,0),
but no error. The zero defines the length of the sample,
not its location. The swap still works. Tried it with this:

txt="abcdefghi"
n1=1
n2=5
temp1=mid(txt,n1,1)
temp2=mid(txt,n2,1)
msgbox left(txt,0)
txt=left(txt,n1-1) & temp2 & mid(txt,n1+1)
txt=left(txt,n2-1) & temp1 & mid(txt,n2+1)
msgbox txt & vbCRLF & "abcdefghi"

-- 
Crash

"Celibacy is the worst form of self-abuse."
~ Peter De Vries ~

[toc] | [prev] | [next] | [standalone]


#11524

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-01-05 12:17 +0100
Message-ID<XnsA6F47D0A7391Ceejj99@194.109.6.166>
In reply to#11522
"Dave \"Crash\" Dummy" <invalid@invalid.invalid> wrote on 05 Jan 2017 in 
microsoft.public.scripting.vbscript:

> Evertjan. wrote:
>> "Dave \"Crash\" Dummy" <invalid@invalid.invalid> wrote on 05 Jan 2017 in
>> microsoft.public.scripting.vbscript: 
>> 
>>> Evertjan. wrote:
>>>> It is a pity that VBS has only the mid() function and has lost the
>>>> mid() statement found in earlier forms of Basic, because there the
>>>> swap-function would have looked like:
>>>> temp = mid(txt,n1,1)
>>>> mid(txt,n1,1) = mid(txt,n2,1)
>>>> mid(txt,n2,1) = temp
>>> You can still come close:
>>>
>>> temp1=mid(txt,n1,1)
>>> temp2=mid(txt,n2,1)
>>> txt=left(txt,n1-1) & temp2 & mid(txt,n1+1)
>>> txt=left(txt,n2-1) & temp1 & mid(txt,n2+1)
>> 
>> Not that simple, 
>> as when n1 or n2 is 1,
>> you will get an error.
>> 
>> left(txt,0) 
>> should, imho, return "", 
>> but it fails to do that in VBS.
> 
> I don't get an error. I get a zero length string for left(txt,0),
> but no error. The zero defines the length of the sample,
> not its location. The swap still works. Tried it with this:
> 
> txt="abcdefghi"
> n1=1
> n2=5
> temp1=mid(txt,n1,1)
> temp2=mid(txt,n2,1)
> msgbox left(txt,0)
> txt=left(txt,n1-1) & temp2 & mid(txt,n1+1)
> txt=left(txt,n2-1) & temp1 & mid(txt,n2+1)
> msgbox txt & vbCRLF & "abcdefghi"

Okay! 

<%
tx = "abcdefghi"
old = tx : response.write "old: " & old & "<br><br>"
n1 = 1 : temp1 = mid(tx,n1,1)
n2 = 5 : temp2 = mid(tx,n2,1)

tx = rp1(tx, n1, temp2)
tx = rp1(tx, n2, temp1)

response.write "string replace: " & tx & "<br><br>"

tx = old

tx = rp2(tx, n1, temp2)
tx = rp2(tx, n2, temp1)

response.write "regex replace: " & tx & "<br>"

function rp1(str,beg,letter)
	rp1 = left(str,beg-1) & letter & mid(str,beg+1)
end function

function rp2(str,beg,letter)
	Set myRegExp = New RegExp
	myRegExp.Pattern = "^(.{" & beg-1 & "})."
	rp2 = myRegExp.replace(str,"$1"&letter)
end function

%>



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#11525

From"Mayayana" <mayayana@invalid.nospam>
Date2017-01-05 09:38 -0500
Message-ID<o4lll9$j8d$1@dont-email.me>
In reply to#11517
"Dave "Crash" Dummy" <invalid@invalid.invalid> wrote

| > temp = mid(txt,n1,1)
| > mid(txt,n1,1) = mid(txt,n2,1)
| > mid(txt,n2,1) = temp
|
| You can still come close:
|

    It's not hard to work around the Mid statement,
but it's very inefficient, requiring the allocation of
new strings. With large strings it gets *very* slow.
The Mid statement treats the string like an array,
replacing existing characters with new ones. So you
don't need to do s = Left(s1, x) & s2 & Right(s1, y)
You just paste s2 into the existing string at offset
x. It's a direct write with no allocations.

   I use that method in VB6 to rebuild strings with
amazing speed. I use a SafeArray structure to
point at the memory used by the string and treat
it as an array. Then I tokenize the string numerically,
walking the array and dealing with characters as
numbers. At the same time I allocate a string big
enough to hold my rebuild and just Mid into it. If
VBS could do that it could help a lot to avoid the
clumsy process of string snipping and pasting with
variants.

 

[toc] | [prev] | [next] | [standalone]


#11530

From"Dave \"Crash\" Dummy" <invalid@invalid.invalid>
Date2017-01-05 13:11 -0500
Message-ID<o4m25p$3gp$1@dont-email.me>
In reply to#11525
Mayayana wrote:
> "Dave "Crash" Dummy" <invalid@invalid.invalid> wrote
> 
> | > temp = mid(txt,n1,1)
> | > mid(txt,n1,1) = mid(txt,n2,1)
> | > mid(txt,n2,1) = temp
> |
> | You can still come close:
> |
> 
>     It's not hard to work around the Mid statement,
> but it's very inefficient, requiring the allocation of
> new strings. With large strings it gets *very* slow.
> The Mid statement treats the string like an array,
> replacing existing characters with new ones. So you
> don't need to do s = Left(s1, x) & s2 & Right(s1, y)
> You just paste s2 into the existing string at offset
> x. It's a direct write with no allocations.

I thought the point was that you could not use mid() to paste a string
into the string in VBScript.

>    I use that method in VB6 to rebuild strings with
> amazing speed. I use a SafeArray structure to
> point at the memory used by the string and treat
> it as an array. Then I tokenize the string numerically,
> walking the array and dealing with characters as
> numbers. At the same time I allocate a string big
> enough to hold my rebuild and just Mid into it. If
> VBS could do that it could help a lot to avoid the
> clumsy process of string snipping and pasting with
> variants.
> 
>  
> 
> 

-- 
Crash

"The future ain't what it used to be."
~ Yogi Berra ~

[toc] | [prev] | [next] | [standalone]


#11531

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-01-05 22:42 +0100
Message-ID<XnsA6F4E6FB9FF3eejj99@194.109.6.166>
In reply to#11530
"Dave \"Crash\" Dummy" <invalid@invalid.invalid> wrote on 05 Jan 2017 in 
microsoft.public.scripting.vbscript:

> I thought the point was that you could not use mid() to paste a string
> into the string in VBScript.

There is no mid()-statement in VBS, 
only a mid()-function.

There was mid()-statement in earlier Basic's,
possibly introduced by the Basic a young man called
William Gates wrote for DOS and for Central Data.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#11532

From"Dave \"Crash\" Dummy" <invalid@invalid.invalid>
Date2017-01-05 17:35 -0500
Message-ID<o4mhk7$u1m$1@dont-email.me>
In reply to#11531
Evertjan. wrote:
> "Dave \"Crash\" Dummy" <invalid@invalid.invalid> wrote on 05 Jan 2017 in 
> microsoft.public.scripting.vbscript:
> 
>> I thought the point was that you could not use mid() to paste a string
>> into the string in VBScript.
> 
> There is no mid()-statement in VBS, 
> only a mid()-function.
> 
> There was mid()-statement in earlier Basic's,
> possibly introduced by the Basic a young man called
> William Gates wrote for DOS and for Central Data.

Basic precludes Bill Gates by a decade. I first learned Basic in the
60's, but I don't remember if that generation had a "mid" statement or
function. It was "string code" as opposed to "object oriented code."

-- 
Crash

English is not my native tongue; I'm an American.

[toc] | [prev] | [next] | [standalone]


#11535

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-01-06 00:46 +0100
Message-ID<XnsA6F57CF5B162eejj99@194.109.6.166>
In reply to#11532
"Dave \"Crash\" Dummy" <invalid@invalid.invalid> wrote on 05 Jan 2017 in 
microsoft.public.scripting.vbscript:

>> There was mid()-statement in earlier Basic's,
>> possibly introduced by the Basic a young man called
>> William Gates wrote for DOS and for Central Data.
> 
> Basic precludes Bill Gates by a decade. I first learned Basic in the
> 60's, but I don't remember if that generation had a "mid" statement or
> function. It was "string code" as opposed to "object oriented code."

I doubt that it 'precludes', it rather predates.

However, this boy William introduced some syntax we still use today,
when writing 'Altair Basic', 'DOS Basic' and 'Central Data Basic',
and I vaguely think that were the string-manipulators left$, mid$, right$.

==========================

You can call him on the number in Albuquerque, NM below: 

"8K RESERVED WORDS INCLUDE ALL THOSE ABOVE, AND IN ADDITION ASC AND ATN CHR
$ CLOAD CONT COS CSAVE DEF EXP FN FRE INP LEFT$ LEN LOG MID$ NULL ON OR NOT 
OUT PEEK POKE POS RIGHT SPC( STR$ TAN VAL WAIT Remember, in the 4K version 
of BASIC variable names are only a letter"

"If any immediate problems with MITS software are encountered, feel free to 
give us a call at (505), 265-7553. The Software Department is at Ext. 3; and 
the joint authors of the ALTAIR BASIC Interpreter, Bill Gates, Paul Allen 
and Monte Davidoff, will be glad to assist you."

<http://www.altair32.com/pdf/Altair_8800_BASIC_Reference_Manual_1975.PDF>


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#11537

From"Dave \"Crash\" Dummy" <invalid@invalid.invalid>
Date2017-01-05 21:03 -0500
Message-ID<o4mtqu$7uv$1@dont-email.me>
In reply to#11535
Evertjan. wrote:
> "Dave \"Crash\" Dummy" <invalid@invalid.invalid> wrote on 05 Jan 2017 in 
> microsoft.public.scripting.vbscript:
> 
>>> There was mid()-statement in earlier Basic's,
>>> possibly introduced by the Basic a young man called
>>> William Gates wrote for DOS and for Central Data.

>> Basic precludes Bill Gates by a decade. I first learned Basic in the
>> 60's, but I don't remember if that generation had a "mid" statement or
>> function. It was "string code" as opposed to "object oriented code."
> 
> I doubt that it 'precludes', it rather predates.

You're right. I'm getting sloppy. Thank you.
-- 
Crash

"Celibacy is the worst form of self-abuse."
~ Peter De Vries ~

[toc] | [prev] | [next] | [standalone]


#11533

From"Mayayana" <mayayana@invalid.nospam>
Date2017-01-05 18:41 -0500
Message-ID<o4mlfq$fad$1@dont-email.me>
In reply to#11530
"Dave "Crash" Dummy" <invalid@invalid.invalid> wrote

| > You just paste s2 into the existing string at offset
| > x. It's a direct write with no allocations.
|
| I thought the point was that you could not use mid() to paste a string
| into the string in VBScript.
|

  Yes, that's what I'm saying. In VB6 there's a
Mid statement that allows one to paste into a
string. and it really is a paste. It's very fast,
treating the string as an array and replacing
any number of characters directly. One
can't use the Mid *function* to do anything
but retrieve part of a string.

Mid statement:
Mid(string, start, [optional length to replace]) = replacementString

s = "abcdefghijklmnop"
s1 = "apple"
Mid(s, 3, 4) = s1

Result:  s = "abapplghijklmnop"


[toc] | [prev] | [next] | [standalone]


#11497

FromUlrich Möller <knobbi38@arcor.de>
Date2017-01-03 15:03 +0100
Message-ID<o4gasu$rrm$1@dont-email.me>
In reply to#11493
Hi Rudy,

Am 03.01.2017 um 13:40 schrieb R.Wieser:
> I need to remove, in a string, a number of characters between two points.
> Currently I'm dong that with
>
> sText = left(sText, RangeBegin-1) & mid(sText, RangeEnd+1)
>
> , but as I have to do that quite a few times in a rather large string (1
> MByte) the whole thing gets mighty slow (probably because of the
> again-and-again recreation of the string).
>
> So, I'm looking for a more economical (read: faster) way to do the same.
>
> The problem is that VBScript doesn't do simple overwriting, and the
> "replace" command does not accept a start position -- or rather it does, but
> that one throws everything away before that point, making it useless to me.
> :-\
maybe this is interesting for you: 
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c19367/VBScript-String-Concatenation-And-Why-It-Should-Be-Avoided-Like-The-Plague.htm

Depending on your exact problem the array method is a more preferable 
method instead of simple string concatenations.

Ulrich

[toc] | [prev] | [next] | [standalone]


#11499

FromUlrich Möller <knobbi38@arcor.de>
Date2017-01-03 15:26 +0100
Message-ID<o4gc73$18n$1@dont-email.me>
In reply to#11497
test snippet for using ado stream for concatenating strings:

set buffer = WScript.CreateObject("ADODB.Stream")
buffer.Open
buffer.type = 2
buffer.WriteText("String1")
buffer.WriteText("String2")
buffer.position = 0
strTemp = buffer.readText()
buffer.close
set buffer = Nothing

Ulrich

[toc] | [prev] | [next] | [standalone]


#11504 — Re: How to economically(!) remove a range of unknown(!) charactersfrom a string

From"R.Wieser" <address@not.available>
Date2017-01-03 17:33 +0100
SubjectRe: How to economically(!) remove a range of unknown(!) charactersfrom a string
Message-ID<586bd184$0$21415$e4fe514c@news.xs4all.nl>
In reply to#11499
Ulrich,

> test snippet for using ado stream for concatenating strings:

That method also passed my mind as a possibility.   I did however not assume
it would be faster than an in-memory method, but I could be wrong in that
...

Goddamn, clumsy hacks like that makes me think back to my time with DOS and
text filtering using batch files/commands. :-\

Regards,
Rudy Wieser


-- Origional message:
Ulrich Möller <knobbi38@arcor.de> schreef in berichtnieuws
o4gc73$18n$1@dont-email.me...
> test snippet for using ado stream for concatenating strings:
>
> set buffer = WScript.CreateObject("ADODB.Stream")
> buffer.Open
> buffer.type = 2
> buffer.WriteText("String1")
> buffer.WriteText("String2")
> buffer.position = 0
> strTemp = buffer.readText()
> buffer.close
> set buffer = Nothing
>
> Ulrich
>

[toc] | [prev] | [next] | [standalone]


#11502 — Re: How to economically(!) remove a range of unknown(!) charactersfrom a string

From"R.Wieser" <address@not.available>
Date2017-01-03 17:26 +0100
SubjectRe: How to economically(!) remove a range of unknown(!) charactersfrom a string
Message-ID<586bd08b$0$21485$e4fe514c@news.xs4all.nl>
In reply to#11497
Ulrich,

> ... the array method is a more preferable method instead of
> simple string concatenations.

:-) Mayayana just reminded me of the same.   Thanks for the suggestion.

Regards,
Rudy Wieser


-- Origional message:
Ulrich Möller <knobbi38@arcor.de> schreef in berichtnieuws
o4gasu$rrm$1@dont-email.me...
> Hi Rudy,
>
> Am 03.01.2017 um 13:40 schrieb R.Wieser:
> > I need to remove, in a string, a number of characters between two
points.
> > Currently I'm dong that with
> >
> > sText = left(sText, RangeBegin-1) & mid(sText, RangeEnd+1)
> >
> > , but as I have to do that quite a few times in a rather large string (1
> > MByte) the whole thing gets mighty slow (probably because of the
> > again-and-again recreation of the string).
> >
> > So, I'm looking for a more economical (read: faster) way to do the same.
> >
> > The problem is that VBScript doesn't do simple overwriting, and the
> > "replace" command does not accept a start position -- or rather it does,
but
> > that one throws everything away before that point, making it useless to
me.
> > :-\
> maybe this is interesting for you:
>
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c19367/VBS
cript-String-Concatenation-And-Why-It-Should-Be-Avoided-Like-The-Plague.htm
>
> Depending on your exact problem the array method is a more preferable
> method instead of simple string concatenations.
>
> Ulrich

[toc] | [prev] | [next] | [standalone]


#11498

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-01-03 15:06 +0100
Message-ID<XnsA6F299C5DA1EBeejj99@194.109.6.166>
In reply to#11493
"R.Wieser" <address@not.available> wrote on 03 Jan 2017 in
microsoft.public.scripting.vbscript: 

> I need to remove, in a string, a number of characters between two
> points. Currently I'm dong that with
> 
> sText = left(sText, RangeBegin-1) & mid(sText, RangeEnd+1)
> 
> , but as I have to do that quite a few times in a rather large string (1
> MByte) the whole thing gets mighty slow (probably because of the
> again-and-again recreation of the string).
> 
> So, I'm looking for a more economical (read: faster) way to do the same.
> 
> The problem is that VBScript doesn't do simple overwriting, and the
> "replace" command does not accept a start position -- or rather it does,
> but that one throws everything away before that point, making it useless
> to me. 
> :-\
> 
> Does anyone have an idea how to do it ?

RegEx is your friend:

sText = "qwerty12345"
RangeBegin = 2
RangeEnd = 6
Range = RangeEnd - RangeBegin

Set myRegExp = New RegExp
myRegExp.Pattern = "^(.{" & RangeBegin & "}).{" & Range & "}"
sText = myRegExp.replace(sText,"$1")
response.write sText ' qw12345




-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#11503

From"R.Wieser" <address@not.available>
Date2017-01-03 17:29 +0100
Message-ID<586bd08b$1$21485$e4fe514c@news.xs4all.nl>
In reply to#11498
Evertjan

> RegEx is your friend:
...
> sText = myRegExp.replace(sText,"$1")

I might be wrong, but is that line above not also a simple concatenation
which is, as its VBS, subject to the same sloppy allocations (as Mayayana
put it) ?

Hmmm .. have to test it I guess

Thanks for the suggestion.

Regards,
Rudy Wieser


-- Origional message:
Evertjan. <exxjxw.hannivoort@inter.nl.net> schreef in berichtnieuws
XnsA6F299C5DA1EBeejj99@194.109.6.166...
> "R.Wieser" <address@not.available> wrote on 03 Jan 2017 in
> microsoft.public.scripting.vbscript:
>
> > I need to remove, in a string, a number of characters between two
> > points. Currently I'm dong that with
> >
> > sText = left(sText, RangeBegin-1) & mid(sText, RangeEnd+1)
> >
> > , but as I have to do that quite a few times in a rather large string (1
> > MByte) the whole thing gets mighty slow (probably because of the
> > again-and-again recreation of the string).
> >
> > So, I'm looking for a more economical (read: faster) way to do the same.
> >
> > The problem is that VBScript doesn't do simple overwriting, and the
> > "replace" command does not accept a start position -- or rather it does,
> > but that one throws everything away before that point, making it useless
> > to me.
> > :-\
> >
> > Does anyone have an idea how to do it ?
>
> RegEx is your friend:
>
> sText = "qwerty12345"
> RangeBegin = 2
> RangeEnd = 6
> Range = RangeEnd - RangeBegin
>
> Set myRegExp = New RegExp
> myRegExp.Pattern = "^(.{" & RangeBegin & "}).{" & Range & "}"
> sText = myRegExp.replace(sText,"$1")
> response.write sText ' qw12345
>
>
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#11500

From"Dave \"Crash\" Dummy" <invalid@invalid.invalid>
Date2017-01-03 11:17 -0500
Message-ID<o4gin9$pee$1@dont-email.me>
In reply to#11493
R.Wieser wrote:
> Hello All,
> 
> I need to remove, in a string, a number of characters between two 
> points. Currently I'm dong that with
> 
> sText = left(sText, RangeBegin-1) & mid(sText, RangeEnd+1)
> 
> , but as I have to do that quite a few times in a rather large string
>  (1 MByte) the whole thing gets mighty slow (probably because of the
>  again-and-again recreation of the string).
> 
> So, I'm looking for a more economical (read: faster) way to do the 
> same.
> 
> The problem is that VBScript doesn't do simple overwriting, and the 
> "replace" command does not accept a start position -- or rather it 
> does, but that one throws everything away before that point, making 
> it useless to me. :-\
> 
> Does anyone have an idea how to do it ?

I'm confused, as usual. Is the string of characters that you want to
remove multiple occurrences of the same string? If so, you can simply
use it as the delimiter in an array then rejoin the elements without the
delimiter:

xString=mid(sText,RangeBegin,RangeEnd-RangeBegin)
sArray=split(sText,xString)
newText=join(sArray,"")

If you are talking about removing multiple unique strings, I'll leave it
to the wordier experts here. :-)

-- 
Crash

"Celibacy is the worst form of self-abuse."
~ Peter De Vries ~

[toc] | [prev] | [next] | [standalone]


#11505

From"R.Wieser" <address@not.available>
Date2017-01-03 17:39 +0100
Message-ID<586bd2b9$0$21429$e4fe514c@news.xs4all.nl>
In reply to#11500
Dave,

> I'm confused, as usual.

Thats not something I can help you with I'm afraid. :-)

> Is the string of characters that you want to remove multiple
> occurrences of the same string?

Unknown (I have no control over what exactly is in the string), but could
be.   If not, I could have used a simple "replace".  :-)

> If so, you can simply use it as the delimiter in an array then
> rejoin the elements without the delimiter:

Would that not also be subject to the same "sloppy allocation" as the method
I posted ?

Regards,
Rudy Wieser


-- Origional message:
Dave "Crash" Dummy <invalid@invalid.invalid> schreef in berichtnieuws
o4gin9$pee$1@dont-email.me...
> R.Wieser wrote:
> > Hello All,
> >
> > I need to remove, in a string, a number of characters between two
> > points. Currently I'm dong that with
> >
> > sText = left(sText, RangeBegin-1) & mid(sText, RangeEnd+1)
> >
> > , but as I have to do that quite a few times in a rather large string
> >  (1 MByte) the whole thing gets mighty slow (probably because of the
> >  again-and-again recreation of the string).
> >
> > So, I'm looking for a more economical (read: faster) way to do the
> > same.
> >
> > The problem is that VBScript doesn't do simple overwriting, and the
> > "replace" command does not accept a start position -- or rather it
> > does, but that one throws everything away before that point, making
> > it useless to me. :-\
> >
> > Does anyone have an idea how to do it ?
>
> I'm confused, as usual. Is the string of characters that you want to
> remove multiple occurrences of the same string? If so, you can simply
> use it as the delimiter in an array then rejoin the elements without the
> delimiter:
>
> xString=mid(sText,RangeBegin,RangeEnd-RangeBegin)
> sArray=split(sText,xString)
> newText=join(sArray,"")
>
> If you are talking about removing multiple unique strings, I'll leave it
> to the wordier experts here. :-)
>
> --
> Crash
>
> "Celibacy is the worst form of self-abuse."
> ~ Peter De Vries ~

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | microsoft.public.scripting.vbscript


csiph-web