473,756 Members | 3,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add/remove space after periods...

I have a textBox that people writes stories in it. They can use [bbcode]
[/bbcode] for format.

I have Aspell installed on the server, so people can make correction to
their text. Sometimes, they forget to add a space after a period. So Aspell
reads the last word of a sentence and the first word of the next sentence as
a single world, which gives an error, word not found.

Before sending the text to Aspell, i add a space after all the periods with:

string = string.replace(/./g, ". ");

I did this for the coma, and it's working, no problem.

But i dont want to add a space after periods in certain [bbcode] [/bbcode].
Because the links will not work.

[link]http://www.tromal.net/index3.php[/link]



I dont know how to do it, but after i added a space to all periods, i could
search for "http" and remove all the space after the periods till the next
"[".

Or the space could only be added when the period is not between
[link][/link] and [img][/img]

Could someone help me on this one, thanks,

André Couturier
www.tromal.net
Jul 23 '05 #1
8 4203
Joseph wrote:
I have a textBox that people writes stories in it. They can use [bbcode] [/bbcode] for format.

I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a space after a period. So Aspell reads the last word of a sentence and the first word of the next sentence as a single world, which gives an error, word not found.

Before sending the text to Aspell, i add a space after all the periods with:
string = string.replace(/./g, ". ");

I did this for the coma, and it's working, no problem.

But i dont want to add a space after periods in certain [bbcode] [/bbcode]. Because the links will not work.

[link]http://www.tromal.net/index3.php[/link]



I dont know how to do it, but after i added a space to all periods, i could search for "http" and remove all the space after the periods till the next "[".

Or the space could only be added when the period is not between
[link][/link] and [img][/img]

Could someone help me on this one, thanks,

André Couturier
www.tromal.net

Not really enough time to test this, but...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled </title>
</head>
<body>
<pre>
<script type="text/javascript">
//<![CDATA[

String.prototyp e.couturierFix = function()
{
var fixer = /([.,])/g;
var refixer = /\. (?=[^\[]*\[\/(link|img)\])/gi;
return this.replace(fi xer, '$1 ').replace(refi xer, '.');
}

var s = [

'Lorem ipsum dolor sit amet,consectetu r adipisicing elit,' ,
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' ,
'Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris ' ,
'nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in ' ,
'reprehenderit in voluptate velit esse cillum dolore eu fugiat ' ,
'nulla pariatur. Excepteur sint occaecat cupidatat non proident,' ,
'sunt in culpa qui officia deserunt mollit anim id est laborum.' ,
'[link]http://www.tromal.net/index3.php[/link]' ,
'

'

];

s = s.join('\n');
document.write( s.couturierFix( ));

//]]>
</script>
</pre>
</body>
</html>

[could write it as stand-alone routine too]

Jul 23 '05 #2
Typo: change to

var fixer = /([.,])[\S]/g;

Thanks.

Jul 23 '05 #3
Joseph wrote:
I have a textBox that people writes stories in it. They can use [bbcode] [/bbcode] for format.

I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a space after a period. So Aspell reads the last word of a sentence and the first word of the next sentence as a single world, which gives an error, word not found.

Before sending the text to Aspell, i add a space after all the periods with:
string = string.replace(/./g, ". ");

I did this for the coma, and it's working, no problem.

But i dont want to add a space after periods in certain [bbcode] [/bbcode]. Because the links will not work.

[link]http://www.tromal.net/index3.php[/link]



I dont know how to do it, but after i added a space to all periods, i could search for "http" and remove all the space after the periods till the next "[".

Or the space could only be added when the period is not between
[link][/link] and [img][/img]

Could someone help me on this one, thanks,

André Couturier
www.tromal.net


This just in....

String.prototyp e.couturierFix = function()
{
var fixer = /([.,])([\S])/g;
var refixer = /\. (?=[^\[]*\[\/(link|img)\])/gi;
return this.replace(fi xer, '$1 $2').replace(re fixer, '.');
}

Use like any other string method:
textBoxRef.valu e = textBoxRef.valu e.couturierFix( );

Jul 23 '05 #4
Joseph wrote:
I have a textBox that people writes stories in it. They can use [bbcode] [/bbcode] for format.

I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a space after a period. So Aspell reads the last word of a sentence and the first word of the next sentence as a single world, which gives an error, word not found.

Before sending the text to Aspell, i add a space after all the periods with:
string = string.replace(/./g, ". ");

I did this for the coma, and it's working, no problem.

But i dont want to add a space after periods in certain [bbcode] [/bbcode]. Because the links will not work.

[link]http://www.tromal.net/index3.php[/link]



I dont know how to do it, but after i added a space to all periods, i could search for "http" and remove all the space after the periods till the next "[".

Or the space could only be added when the period is not between
[link][/link] and [img][/img]

Could someone help me on this one, thanks,

André Couturier
www.tromal.net


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled </title>
</head>
<body style="width:57 8px;margin:100p x auto;font:9pt
verdana;text-align:justify;b ackground:#eef; ">
<script type="text/javascript">
//<![CDATA[

String.prototyp e.couturierFix = function()
{
return this.replace(/([.,])([\S])/g, '$1 $2').
replace(/\. (?=[^[]*\[\/(link|img)\])/gi, '.');
}

var s = [

'Lorem ipsum dolor sit amet,consectetu r adipisicing elit,' ,
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' ,
'Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris ' ,
'nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in ' ,
'reprehenderit in voluptate velit esse cillum dolore eu fugiat ' ,
'nulla pariatur. Excepteur sint occaecat cupidatat non proident,' ,
'sunt in culpa qui officia deserunt mollit anim id est laborum.' ,
'<br /><br />[link]http://www.tromal.net/index3.php[/link]' ,
'<br /><br />

<br />'

];

document.write(

'|before|' ,
'<br /><br />' ,
(s = s.join('')) ,
'<hr /><br />' ,
'|after|<br /><br />' ,
s.couturierFix( )

);

//]]>
</script>
</body>
</html>

Think that helps. Use like any other string method:
textBoxRef.valu e = textBoxRef.valu e.couturierFix( );

Jul 23 '05 #5
Joseph wrote:
I have a textBox that people writes stories in it. They can use [bbcode] [/bbcode] for format.

I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a space after a period. So Aspell reads the last word of a sentence and the first word of the next sentence as a single world, which gives an error, word not found.

Before sending the text to Aspell, i add a space after all the periods with:
string = string.replace(/./g, ". ");

I did this for the coma, and it's working, no problem.

But i dont want to add a space after periods in certain [bbcode] [/bbcode]. Because the links will not work.

[link]http://www.tromal.net/index3.php[/link]



I dont know how to do it, but after i added a space to all periods, i could search for "http" and remove all the space after the periods till the next "[".

Or the space could only be added when the period is not between
[link][/link] and [img][/img]

Could someone help me on this one, thanks,

André Couturier
www.tromal.net


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled </title>
</head>
<body style="width:57 8px;margin:100p x auto;font:9pt
verdana;text-align:justify;b ackground:#eef; ">
<script type="text/javascript">
//<![CDATA[

String.prototyp e.couturierFix = function()
{
return this.replace(/([.,])([\S])/g, '$1 $2').
replace(/\. (?=[^[]*\[\/(link|img)\])/gi, '.');
}

var s = [

'Lorem ipsum dolor sit amet,consectetu r adipisicing elit,' ,
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' ,
'Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris ' ,
'nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in ' ,
'reprehenderit in voluptate velit esse cillum dolore eu fugiat ' ,
'nulla pariatur. Excepteur sint occaecat cupidatat non proident,' ,
'sunt in culpa qui officia deserunt mollit anim id est laborum.' ,
'<br /><br />[link]http://www.tromal.net/index3.php[/link]' ,
'<br /><br />

<br />'

];

document.write(

'|before|' ,
'<br /><br />' ,
(s = s.join('')) ,
'<hr /><br />' ,
'|after|<br /><br />' ,
s.couturierFix( )

);

//]]>
</script>
</body>
</html>

Think that helps. Use like any other string method:
textBoxRef.valu e = textBoxRef.valu e.couturierFix( );

Jul 23 '05 #6
JRS: In article <AN************ *********@weber .videotron.net> , dated
Sat, 18 Dec 2004 17:05:00, seen in news:comp.lang. javascript, Joseph
<mi**@moimiom.o rg> posted :
I have a textBox that people writes stories in it. They can use [bbcode]
[/bbcode] for format.

I have Aspell installed on the server, so people can make correction to
their text. Sometimes, they forget to add a space after a period. So Aspell
reads the last word of a sentence and the first word of the next sentence as
a single world, which gives an error, word not found.

Before sending the text to Aspell, i add a space after all the periods with:

string = string.replace(/./g, ". ");

I did this for the coma, and it's working, no problem.

But i dont want to add a space after periods in certain [bbcode] [/bbcode].

There are many other cases where a space should not be added.

There are 3,5 miles to go;
there is .5 mile to go;
this is news:comp.lang. javascript;
in Ascii, one must write "..." for an ellipsis;
etc., etc.

Space correcting is not programmable, except possibly by experts in
computing and language. Make the writers get it right, or use a human
editor.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7
Dr John Stockton wrote:

(snip)
Space correcting is not programmable, except possibly by experts in
computing and language. Make the writers get it right, or use a human editor.


Doubtless so, but imperious nonetheless. Let them eat spaces.
Work-in-progress, maybe useful to the OP:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>shoot me</title>
<style type="text/css">

body {
font: normal 100% arial, sans-serif;
background: #900;
}
#p1, #p2, #p3, #p4, #p5, #p6 {
width: 340px;
font: normal 70% arial, sans-serif;
padding: 8px;
margin: 0 auto;
border: 1px #fff dashed;
background: #faf0e0;
}
button {
display: block;
width: 100px;
margin: 8px auto;
}

</style>
<script type="text/javascript">
//<![CDATA[

String.prototyp e.couturierFix = function()
{
return this.replace(/(\D[.!?])(?=[^ .a-z\d])/g, '$1 ').
replace(/,(?=[\S])/g, ', ').
replace(/\. (?=[^[]*\[\/(link|img)\])/gi, '.');
}

function fixit()
{
var p, i = 1, fixed;
while (p = document.getEle mentById('p' + i++))
{
fixed = p.firstChild.no deValue.couturi erFix();
p.replaceChild( document.create TextNode(fixed) , p.firstChild);
}
return false;
}

//]]>
</script>
</head>
<body>
<p id="p1">&nbsp;
When a girl leaves her home at eighteen,she does one of two
things.Either she falls into saving hands and becomes better, or she
rapidly assumes the cosmopolitan standard of virtue and becomes worse.
Of an intermediate balance, under the circumstances, there is no
possibility.The city has its cunning wiles,no less than the infinitely
smaller and more human tempter. There are large forces which allure
with all the soulfulness of expression possible in the most cultured
human. The gleam of a thousand lights is often as effective as the
persuasive light in a wooing and fascinating eye. Half the undoing of
the unsophisticated and natural mind is accomplished by forces wholly
superhuman. A blare of sound, a roar of life, a vast array of human
hives,appeal to the astonished senses in equivocal terms. Without a
counsellor at hand to whisper cautious interpretations ,what falsehoods
may not these things breathe into the unguarded ear!Unrecognise d for
what they are, their beauty, like music, too often relaxes,then
weakens,then perverts the simpler human perceptions.
</p>
<p id="p2">
Link test:


</p>
<p id="p3">
Image test:


</p>
<p id="p4">
Question mark test: fixes question marks?Hopefully ...
</p>
<p id="p5">
Exclamation point test: Exclamation points!Yes/no?Maybe?
</p>
<p id="p6">
Decimal / ellipsis test: there is .5 mile to go...correct?
</p>
<button onclick="return fixit()">fix it</button>
<button onclick="locati on.reload()">re store</button>
</body>
</html>

Jul 23 '05 #8

"RobB" <fe******@hotma il.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Dr John Stockton wrote:

(snip)
Space correcting is not programmable, except possibly by experts in
computing and language. Make the writers get it right, or use a

human
editor.


Doubtless so, but imperious nonetheless. Let them eat spaces.
Work-in-progress, maybe useful to the OP:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>shoot me</title>
<style type="text/css">

body {
font: normal 100% arial, sans-serif;
background: #900;
}
#p1, #p2, #p3, #p4, #p5, #p6 {
width: 340px;
font: normal 70% arial, sans-serif;
padding: 8px;
margin: 0 auto;
border: 1px #fff dashed;
background: #faf0e0;
}
button {
display: block;
width: 100px;
margin: 8px auto;
}

</style>
<script type="text/javascript">
//<![CDATA[

String.prototyp e.couturierFix = function()
{
return this.replace(/(\D[.!?])(?=[^ .a-z\d])/g, '$1 ').
replace(/,(?=[\S])/g, ', ').
replace(/\. (?=[^[]*\[\/(link|img)\])/gi, '.');
}

function fixit()
{
var p, i = 1, fixed;
while (p = document.getEle mentById('p' + i++))
{
fixed = p.firstChild.no deValue.couturi erFix();
p.replaceChild( document.create TextNode(fixed) , p.firstChild);
}
return false;
}

//]]>
</script>
</head>
<body>
<p id="p1">&nbsp;
When a girl leaves her home at eighteen,she does one of two
things.Either she falls into saving hands and becomes better, or she
rapidly assumes the cosmopolitan standard of virtue and becomes worse.
Of an intermediate balance, under the circumstances, there is no
possibility.The city has its cunning wiles,no less than the infinitely
smaller and more human tempter. There are large forces which allure
with all the soulfulness of expression possible in the most cultured
human. The gleam of a thousand lights is often as effective as the
persuasive light in a wooing and fascinating eye. Half the undoing of
the unsophisticated and natural mind is accomplished by forces wholly
superhuman. A blare of sound, a roar of life, a vast array of human
hives,appeal to the astonished senses in equivocal terms. Without a
counsellor at hand to whisper cautious interpretations ,what falsehoods
may not these things breathe into the unguarded ear!Unrecognise d for
what they are, their beauty, like music, too often relaxes,then
weakens,then perverts the simpler human perceptions.
</p>
<p id="p2">
Link test:


</p>
<p id="p3">
Image test:


</p>
<p id="p4">
Question mark test: fixes question marks?Hopefully ...
</p>
<p id="p5">
Exclamation point test: Exclamation points!Yes/no?Maybe?
</p>
<p id="p6">
Decimal / ellipsis test: there is .5 mile to go...correct?
</p>
<button onclick="return fixit()">fix it</button>
<button onclick="locati on.reload()">re store</button>
</body>
</html>


=============== =====
Your hot! Thank-you very much for the script. I dont understand it, but it
works great ! :o)

Here is the script that i use for formating and preventing abuse when people
writes stories:
string = document.formna me.story.value;

// check for banned words
var bannedWordArray = new Array(" pa ", " ki ", " ds "," ke "," g "," tro
"," fo "," kan "," tou "," lè "," tjrs "," koi "," kelke "," pe "," ya ","
dla "," po "," ns "," ù "," jvous "," keske ", " pr ", " moa ", " pk ", " mé
", " mem ", " ossi ");
var bannedWordCount = 26;
for (i = 0; i <= bannedWordCount ; i++) {
var bannedWordDetec ted = string.indexOf( bannedWordArray[i]);
if (bannedWordDete cted != -1) { var messageError = 'banned words
detected';}
}

// remove repeating characters
string = stripToLong(str ing);

// format text for periods and commas
string = string.couturie rFix();

// remove double space
string = string.replace(/ /g, " ");

// remove space before commas
string = string.replace(/ ,/g, ",");
// end
// -------------- functions

// format text for period, comma
String.prototyp e.couturierFix = function() {
return this.replace(/(\D[.!?])(?=[^ .a-z\d])/g, '$1 ').
replace(/,(?=[\S])/g, ', ').
replace(/ \.(?=[\S])/g, '.').
replace(/\. (?=[^[]*\[\/(lien|image)\])/gi, '.');
}
// limit repeating characters
function stripToLong(str ing) {
var accumulator = new Array();
var current = "";
var count = 0;
for (i = 0;i < string.length; i++) {
var c = string.charAt(i );
if (c == current) {
count++;
} else {
count = 1;
current = c;
}
if (count <= 4) {
accumulator[i] = c;
}
}
return accumulator.joi n("");
}

-----------------

Thanks again,
André Couturier
www.tromal.net

Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2864
by: JT | last post by:
i have written some asp that reads a fixed length text file, line by line, inserting each line into my database. my problem is that the text file format seems to have extra space at the end of the file so my code thinks there is actually one more line when there is not. is there a way to remove these spaces before i loop through the file? here is my sample code: Do While df.AtEndOfStream <> True line = df.ReadLine
9
41458
by: Daniel | last post by:
Hi I'd like to discuss the following problem: How to remove the space between two images (img)? <img alt="First" src="first.gif"> <img alt="Second" src="second.gif"> I tried:
2
1582
by: Beffmans | last post by:
Hi How do i remove the space below the 'hello'? <TABLE> <tbody> <tr> <td> <asp:panel id="pnlTop" Runat="server"> <TABLE>
8
3020
by: voroojak | last post by:
i want to remove space in my table. it is a text box and i want to remove the space after the character. the field is integer thanks aot
9
2659
by: voroojak | last post by:
I cant remove the space in my table. i used Trim and replace. but still it sis not working. Dim campign_number As Integer campaign_number = Trim(Me.tbx_campaign_number) With rst .AddNew .Fields("campaign_number") = campaign_number i dont know what to do. HELPPPPPPPPPPPPPPPP
5
4166
by: Steve | last post by:
I'm getting string returned from my Database with a space in front of it, it sometimes it looks like this 8 9 10 1 and so one, how can I remove the white space in front of the numbers? Its actually causing an error on one of my pages and I'm not sure how to remove it in the beginning of the string.
4
2604
by: ashish1779 | last post by:
hi I am new in PHP, i have face one problem when I crawl any site and i have to save the whole HTML content in database, on that time all the HTML tags are changes into the extra space in content then it is saved into DB.i want to remove that extra space from content when we have to use them . and i am not understand what how remove that space or say tags which is not shown in my contents
6
4193
by: Mladen Mavrovic | last post by:
Hi everyone, I have to fix this asap, and I tried all I know, but there was no joy. Please, take a look at http://stampamajica.in.rs/ There are 3 html pages there. Can anybody tell me how to fix the code to remove space between images in ie8? Your help is very much appreciated!
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10032
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9841
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5141
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.