?
Solved

Justify and count

Posted on 2009-03-29
4
Medium Priority
?
180 Views
Last Modified: 2012-06-27
Hi

Does anyone know if its possible to left-justfy text in a <textarea>?
and count the instances of each distinct string?

Best regards

Letchev
<textarea cols=20 rows=20> 
Law, Economics
and Management),
   Centre d'Études
d'Études en
   Macroéconomie et
  Finance Internationale
Macroéconomie et
Internationale (CEMAFI)
  (Center for
in Macroeconomics
  and International
International Finance)
Finance) Université
   de droit,
droit, d'economie
 and International
de droit
</textarea>
 
after justify
=========
 
<textarea cols=20 rows=20> 
Law, Economics
and Management),
Centre d'Études
d'Études en
Macroéconomie et
Finance Internationale
Macroéconomie et
Internationale (CEMAFI)
(Center for
in Macroeconomics
and International
International Finance)
Finance) Université
de droit,
droit, d'economie
and International
de droit
</textarea>
After to justify
============
 
<textarea cols=20 rows=20> 
Law, Economics = 1
and Management), = 1
Centre d'Études = 1
d'Études en = 1
Macroéconomie et = 1
Finance Internationale = 1
Macroéconomie et = 1
Internationale (CEMAFI) = 1
(Center for = 1
in Macroeconomics = 1
and International = 2
International Finance) = 1
Finance) Université = 1
de droit,  = 2
droit, d'economie = 1
t
</textarea>

Open in new window

0
Comment
Question by:letchev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 30

Accepted Solution

by:
third earned 1000 total points
ID: 24012414
below is an example how to left justify.

I'm not sure of the example on counting the distinct string though. can you elaborate?
<!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/1999/xhtml">
<head>
<title>Third Santor</title>
<script>
function format(){
  var mem1 = document.getElementById('mem1');
  if(mem1){
    strArr = mem1.value.split('\n');
	for(var i=0; i<strArr.length; i++){
	  var str = strArr[i];
	  while(str.indexOf(' ')==0){
	    str = str.substring(1);
	  }
	  strArr[i] = str;
	}
    mem1.value = strArr.join('\n');
  }
}
</script>
</head>
<body>
<textarea id="mem1" cols="30" rows="20"> 
Law, Economics
and Management),
   Centre d'Études
d'Études en
   Macroéconomie et
  Finance Internationale
Macroéconomie et
Internationale (CEMAFI)
  (Center for
in Macroeconomics
  and International
International Finance)
Finance) Université
   de droit,
droit, d'economie
 and International
de droit
</textarea>
<input type="button" value="Click" onclick="format()" />
</body>
</html>

Open in new window

0
 
LVL 12

Expert Comment

by:alien109
ID: 24013131
use regular expressions to remove the leading white space:

var mem1 = document.getElementById('mem1');

mem1.value = mem1.value.replace(/^\s+/, '');

to get the number of lines, the quickest (although not most elegant) solution is

count = mem1.value.split(/\n/).length;
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 37089693
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question