Cut String & Insert in String

Discussion in 'ASP General' started by vunet.us@gmail.com, May 14, 2007.

  1. Guest

    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.
     
    , May 14, 2007
    #1
    1. Advertising

  2. wrote:
    > 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

    --
    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.
     
    Bob Barrows [MVP], May 14, 2007
    #2
    1. Advertising

  3. Guest

    On May 14, 12:06 pm, "Bob Barrows [MVP]" <>
    wrote:
    > wrote:
    > > 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/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
     
    , May 14, 2007
    #3
  4. Evertjan. Guest

    Bob Barrows [MVP] wrote on 14 mei 2007 in
    microsoft.public.inetserver.asp.general:

    >> 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
    >


    > 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>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., May 14, 2007
    #4
  5. Evertjan. wrote:

    >> 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>


    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.

    --
    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.
     
    Bob Barrows [MVP], May 14, 2007
    #5
  6. Evertjan. Guest

    Bob Barrows [MVP] wrote on 14 mei 2007 in
    microsoft.public.inetserver.asp.general:

    > Evertjan. wrote:
    >
    >>> 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>

    >
    > 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.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., May 14, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Collins

    cut a string in file

    Ian Collins, Mar 30, 2008, in forum: C++
    Replies:
    4
    Views:
    1,254
    Default User
    Mar 30, 2008
  2. Christopher Brandsdal

    cut from string using JScript

    Christopher Brandsdal, Jun 3, 2004, in forum: ASP General
    Replies:
    10
    Views:
    236
    Christopher Brandsdal
    Jun 4, 2004
  3. Christopher Brandsdal

    cut something from a string

    Christopher Brandsdal, Feb 3, 2006, in forum: ASP General
    Replies:
    3
    Views:
    130
    Roland Hall
    Feb 5, 2006
  4. Toki Toki
    Replies:
    4
    Views:
    137
    Toki Toki
    Aug 17, 2008
  5. Pål Bergström

    Cut a string if length > n

    Pål Bergström, Aug 19, 2008, in forum: Ruby
    Replies:
    14
    Views:
    203
    Pål Bergström
    Aug 20, 2008
Loading...

Share This Page