DIGIT-ARC read-only archive · snapshot: July 23, 2026

Can anyone help find some code for me?

4 posts · originally from https://geek.digit.in/community/threads/can-anyone-help-find-some-code-for-me.32490/

B
BJ Dibbins Original post #1
Jul 22, 2006 at 7:10 PM
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
S
Jul 22, 2006 at 9:40 PM
What language should the code be in? Or would you prefer pseudocode?

Arun
rohan
rohan #3
Jul 22, 2006 at 10:22 PM
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" "*www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="*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
B
Jul 23, 2006 at 6:47 AM
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