Can anyone help find some code for me?

Discussion in 'Software Q&A' started by BJ Dibbins, Jul 22, 2006.

Thread Status:
Not open for further replies.
  1. BJ Dibbins

    BJ Dibbins New Member

    Joined:
    Jul 22, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,

    I'm looking for some code and wondering if anyone can help?

    I'd like to be able to extract the first letter of each word that is pasted into an input box on a website.

    For example, if someone entered "It was the best of times, it was the worst of times" the program would return "Iwtbotiwtwot"

    Any ideas?

    Cheers,

    Brian
     
  2. sakumar79

    sakumar79 Active Member

    Joined:
    Nov 28, 2004
    Messages:
    2,441
    Likes Received:
    9
    Trophy Points:
    38
    Location:
    Madurai
    What language should the code be in? Or would you prefer pseudocode?

    Arun
     
  3. rohan

    rohan New Member

    Joined:
    Mar 8, 2004
    Messages:
    299
    Likes Received:
    6
    Trophy Points:
    0
    Location:
    Bangalore
    Since you said 'website', it is possible you want it mostly in JavaScript. Here's a sample page:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html xmlns="http://www.w3.org/1997/xhtml" lang="en" xml:lang="en">
      <head>
       <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"/>
       <title>Extract the first letter of each word</title>
       <script type="text/javascript">
    	<!--
    	var box;
    	var output;
    
    	function onLoad() {
    		box = document.getElementById('user_word');
    		output = document.getElementById('put_string');
    	}
    
    	function process() {
    		var datum = box.value;
    		var out = "";
    		var words = new Array();
    		words = datum.split(" ");
    
    		for(var i=0; i<words.length; i++) {
    			out += words[i].substr(0, 1);
    		}
    
    		output.innerHTML = out;
    	}
    	-->
       </script>
      </head>
    
     <body onload="javascript:onLoad()">
      <p>
       <input type="text" id="user_word" size="20"/><input type="button" value="Go" onclick="javascript:process()"/><br/>
       <span id="put_string"></span>
      </p>
     </body>
    </html>
    
    Hmm.. that's pretty much everything. Hope it helps. -rohan
     
  4. OP
    OP
    BJ Dibbins

    BJ Dibbins New Member

    Joined:
    Jul 22, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi guys,

    Arun, I'm looking for something I could use primarily from a website, so perhaps javascript would be best?

    Rohan, thank you very much for the code - that's pretty much exactly what I was after. I've got a project in mind that would use this function, as well as some further character replacement. If you're interested in developing the code further could you email me so we could discuss it?

    Cheers,

    Brian
     
Thread Status:
Not open for further replies.

Share This Page