www.webdeveloper.com
Results 1 to 3 of 3

Thread: sub string of a string

  1. #1
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    sub string of a string

    is there a ready made function that tell's u if a string contains another string?
    for example :
    str1="abcdef5423"
    str2="def5"
    the i will get
    that start position of str2 in str1 is 6

    i know it available in vbscript

    thanks inadvance
    Peleg

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    <script type="text/javascript">
    <!--
    String.prototype.position = function (s) {this.match(new RegExp('^(.*)' + s)); return RegExp.$1.length}

    alert ('abcdef5423'.position('def5'))
    // -->
    </script>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    String.prototype.position = function (s) {...
    This may require a small change. As it is right now there is no way to tell the whether the search string occurs at the beginning or doesn't occur at all.

    In any case, this is all really unecessary. The indexOf method will perform this job.
    Code:
    alert('abcdef5423'.indexOf('def5'));
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles