Cut String & Insert in String

V

vunet.us

Hello,
In ASP, VBScript:
How can I display the first 20 characters of a long string?
How can I insert some character inside of the string on every 5th
character?
Thank you for help.
 
B

Bob Barrows [MVP]

Hello,
In ASP, VBScript:
How can I display the first 20 characters of a long string?

first20 = left(longstring,20)
How can I insert some character inside of the string on every 5th
character?

There may be a regular expression solution for this, but for
simplicity's sake:

dim i, oldstring,newstring, stringseg,subst_char
for i = 1 to len(oldstring) step 5
stringseg=mid(oldstring,i,5)
if len(newstring) > 0 then
newstring = newstring & subst_char & stringseg
else
newstring=stringseg
end if
next
Thank you for help.

The vbscript documentation can be downloaded from:
http://www.microsoft.com/downloads/...48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en

or it can be read online at
http://msdn2.microsoft.com/en-us/library/t0aew7h6.aspx
 
V

vunet.us

first20 = left(longstring,20)


There may be a regular expression solution for this, but for
simplicity's sake:

dim i, oldstring,newstring, stringseg,subst_char
for i = 1 to len(oldstring) step 5
stringseg=mid(oldstring,i,5)
if len(newstring) > 0 then
newstring = newstring & subst_char & stringseg
else
newstring=stringseg
end if
next


The vbscript documentation can be downloaded from:http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207...

or it can be read online athttp://msdn2.microsoft.com/en-us/library/t0aew7h6.aspx

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

thank you veeeery much
 
E

Evertjan.

Bob Barrows [MVP] wrote on 14 mei 2007 in
microsoft.public.inetserver.asp.general:
There may be a regular expression solution for this, but for
simplicity's sake:

dim i, oldstring,newstring, stringseg,subst_char
for i = 1 to len(oldstring) step 5
stringseg=mid(oldstring,i,5)
if len(newstring) > 0 then
newstring = newstring & subst_char & stringseg
else
newstring=stringseg
end if
next
There may be a regular expression solution for this

"may", "simplicity"?

<%
reponse.write insertFifth('12345678901234567890123','x')
%>

<script language='javascript' runat='server'>
function insertFifth(s,inser){
return s.replace(/(.{5})/g,"$1"+inser);
};
</script>
 
B

Bob Barrows [MVP]

Evertjan. said:
"may", "simplicity"?

<%
reponse.write insertFifth('12345678901234567890123','x')
%>

<script language='javascript' runat='server'>
function insertFifth(s,inser){
return s.replace(/(.{5})/g,"$1"+inser);
};
</script>

Yes! Simplicity!
Go ahead. Tell the user how to interpret that regexp, as well as how to
create it, the next time he needs something like this.

Simplicity isn't always about the number of lines of code involved.
 
E

Evertjan.

Bob Barrows [MVP] wrote on 14 mei 2007 in
microsoft.public.inetserver.asp.general:
Yes! Simplicity!
Go ahead. Tell the user how to interpret that regexp, as well as how to
create it, the next time he needs something like this.

Sorry Bob, I fail to see that.
The earlier vbscirpt example was not explained.

Usenet is an interactive medium, so anyone is free to ask.
Simplicity isn't always about the number of lines of code involved.

Simplicity is in the hands of the beholder.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top