www.webdeveloper.com
Results 1 to 5 of 5

Thread: get all alone letters from string

  1. #1
    Join Date
    Feb 2013
    Posts
    3

    get all alone letters from string

    hello

    i been trying all day to put all letters, into an array from a string
    now i only want letters that have no othere letters around them
    like... im gonna try to give an example
    from "test h lol-k 5b" i would want the result to be an array with ["h","k","b"] (sense they are letters without letters
    beside them)

    sry if its hard to understand, thanks

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,414
    Quote Originally Posted by EnderCrypt View Post
    hello

    i been trying all day to put all letters, into an array from a string
    now i only want letters that have no othere letters around them
    like... im gonna try to give an example
    from "test h lol-k 5b" i would want the result to be an array with ["h","k","b"] (sense they are letters without letters
    beside them)

    sry if its hard to understand, thanks
    I'm not sure I understand your request.
    Why would you not expect the results to be an array of: ['t','t','h','l','k','5','b'] ?
    (All of those have a space beside them)

    For example:
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    </head>
    <body>
    <script type="text/javascript">
    var str = 'test h lol-k 5b';
    var sarr = str.split(' ');
    var tarr = [];
    str = '';
    for (var i=0; i<sarr.length; i++) {
      tarr.push(sarr[i].charAt(0));
      if (sarr[i].length > 1) { tarr.push(sarr[i].charAt(sarr[i].length-1)); }
    }
    alert(tarr);
    </script>
    
    </body>
    </html>
    Last edited by JMRKER; 02-19-2013 at 11:27 AM.

  3. #3
    Join Date
    Feb 2013
    Posts
    3
    well, i want any letter that does not have a letter to the left or to the right

    "test h lol-k 5b"
    ["h","k","b"]

    h has no letters beside it
    k has no letters beside it
    b has no letters be

  4. #4
    Join Date
    Feb 2013
    Posts
    3
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    </head>
    <body>
    <script type="text/javascript">
    var str = 'test h lol-k 5b';
    var sarr = str.split(' ');
    var tarr = [];
    str = '';
    for (var i=0; i<sarr.length; i++) {
      tarr.push(sarr[i].charAt(0));
      if (sarr[i].length > 1) { tarr.push(sarr[i].charAt(sarr[i].length-1)); }
    }
    alert(tarr);
    </script>
    
    </body>
    </html>
    hm, not really
    what i want is all letters, not forming a word (word = more then one letter), so basiclly all letters, not having anotherer letter beside them, its ok if it has signs, or numbers, as long as its not an letter its touch , its really hard to explain, sorry

  5. #5
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,414
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    </head>
    <body>
    <script type="text/javascript">
    var str = 'test h lol-k 5b';
    var sarr = str.split(/[\s|\-|\d]/);
    var tarr = [];
    for (var i=0; i<sarr.length; i++) {
      if (sarr[i].length == 1) { tarr.push(sarr[i]); }
    }
    alert(tarr);
    </script>
    
    </body>
    </html>

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