/    Sign up×
Community /Pin to ProfileBookmark

I was wondering, how can you search for the end of a line in a textarea?

I was copy and pasted some text into a textarea and I just want to grab the first line of the text area, I tried searching using n but this only works if you type something in the text area and hit enter. It also doesn’t work if you don’t hit enter and keep on typing

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@domiereavronauthorDec 04.2008 — okay so I have been playing around I have gotten this so far

[code=html]

<html>

<head>

<script type="text/javascript">




function crline(info, spacing)
{
info = info + spacing.substring(info.length)
return info
}



function spaceit(textToSpace)
{


var lines = textToSpace.split('rn');
var spacing3 =" ";
var pg3text = ""

for (i=0; i < lines.length; i++)
{

pg3text = pg3text + crline(lines[i], spacing3)

}
document.getElementById("tester").innerHTML = "test"
document.getElementById("tester").innerHTML = lines
holdtext.innerText = pg3text;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");


}


</script>

</head>


<body>


<textarea rows=25 cols=75 id="claimtext">

</textarea>

<input type="button" value="test" onclick="spaceit(document.getElementById('claimtext').value)">

<br>

<textarea id="test" rows=25 cols=75></textarea>


<TEXTAREA ID="holdtext" STYLE="display:none;"></TEXTAREA>


<div id="tester"> </div>



</body>




</html>

[/code]


I am trying to take each line it if it is shorter then 75 characters, make it 75 characters long, but for some reason it isn't quite working yet
Copy linkTweet thisAlerts:
@voidvectorDec 04.2008 — I am not really sure what you are asking.

Do you want to grab the first row of text up to the first text wrap? or you want to grab all the text up to the first CR or LF character? Or is it something else?
Copy linkTweet thisAlerts:
@justinbarneskinDec 04.2008 — Just a hint here, escape the vale of the text area and search for the escaped linebreak.
Copy linkTweet thisAlerts:
@domiereavronauthorDec 04.2008 — I am not really sure what you are asking.

Do you want to grab the first row of text up to the first text wrap? or you want to grab all the text up to the first CR or LF character? Or is it something else?[/QUOTE]


In the end, what I am trying to do is take text that I have copied from another source like from an email and paste it into a textarea. The Textarea is 75 columns. I am then splitting each textarea row into an array. Then I want to take each value of the array and have it so that's length is equal to 75 by adding white space to it. The variable spacing3 is 75 spaces " ". If I take the length of the row that I am working with and add the white space. This will have each line exactly 75 chars long

I want to get each line regardless if it is a line break or if it is just a wrap.
Copy linkTweet thisAlerts:
@voidvectorDec 04.2008 — Is this what you want?
[code=html]
<html>
<head>
<script type="text/javascript">

var spacing3 ="...........................................................................";

function replacer(full, substring1, substring2)
{
if (substring2.length)
return substring1 + spacing3.substring(substring1.length) + substring2;
else
return substring1 + spacing3.substring(substring1.length);
}

function spaceit(textToSpace)
{
var lines = textToSpace.replace(/^([^rn]{0,74})([rn]*)/mg, replacer);
document.getElementById("test").value = lines;
}


</script>
</head>


<body>
<textarea rows=25 cols=75 id="claimtext"></textarea>
<input type="button" value="test" onclick="spaceit(document.getElementById('claimtext').value)">
<br>
<textarea id="test" rows=25 cols=76></textarea>
</body>
</html>
[/code]


Text-wrap is not detectable using this method. Characters with varying width such TAB character, other control characters, and non-European character are not handled.
Copy linkTweet thisAlerts:
@domiereavronauthorDec 08.2008 — Well I was trying to take something like

To change your bank account information, we would require either 1) a pre-printed personalized cheque with all or one of the names on your mortgage title or 2) a formal bank change request form provided by your financial institution and signed by the account holder(s). The bank account must be in at least one person's name on title. If faxing a bank change request form, it must be faxed and stamped from your new financial institution.

and turn

To change your bank account information, we would require either 1) a pre- printed personalized cheque with all or one of the names on your mortgage** title or 2) a formal bank change request form provided by your financial**** institution and signed by the account holder(s). The bank account must be* in at least one person's name on title. If faxing a bank change request form, it must be faxed and stamped from your new financial institution.*********

Having all the dead space filled with either asteriks or spaces so that each line is 75 characters long

I have tried different things like replacing the r with n but nothing seems to get the effect that I am looking for
×

Success!

Help @domiereavron spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...