Link to home
Start Free TrialLog in
Avatar of s_hausen
s_hausen

asked on

spliting a paragraph into two sections

Hi,
I am facing a problem in my coldfusion8 application. I need to divide the text in 2 paragraphs, but somehow the words are cutting in the middle of it. For eg: the word READABLE cuts in and left in first paragraph as "REA" and in second paragraph it starts from "DABLE". I am looking for a solution which stops on space or period so user can read it easily.

The sample code is as under:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>

<body>

<cfset stText = "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose."/>

<p id="Page1">
<h1>PARAGRAPH 1</h1>
<cfoutput>
<!---para 1--->
  <cfif IsDefined("VARIABLES.stText") AND VARIABLES.stText NEQ "">
	<cfset stLengthA = Len(VARIABLES.stText) />
	  <cfif VARIABLES.stLengthA LTE 30>
      	#RTrim(VARIABLES.stText)#
      <cfelse>
      	<cfset stDivideA=VARIABLES.stLengthA/2 />
      	<cfset stPrintA = Round(VARIABLES.stDivideA) />
      	#RTrim(left(VARIABLES.stText, stPrintA))# &nbsp;&nbsp; (PARAGRAPH 1, continued on para 2)
      </cfif>
  </cfif>
</p>
<p id="Page2"> 
<!---para 2--->
<h1>PARAGRAPH 2</h1>
  <cfif IsDefined("VARIABLES.stText") AND VARIABLES.stText NEQ "">
	<cfset stLengthB = Len(VARIABLES.stText) />
    <cfif VARIABLES.stLengthB GT 30>
    	<cfset stDivideB=VARIABLES.stLengthB/2 />
    	<cfset stPrintB = Round(VARIABLES.stDivideB) />
    	#LTrim(Right(VARIABLES.stText, (stPrintB)+12))# 
<!---(Using +12 coss text is cutting in between words for eg: (THE WORD "readable", cuts and print ONLY "rea" in first paragraph , so atleast user can read what was the whole sentence when they read in next paragraph, instead of reading from "dable" and most of the time)--->
    </cfif>
  </cfif>
</cfoutput>
</p>
</body>
</html>

Open in new window


The result of the above code as under:

PARAGRAPH 1
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like rea    (PARAGRAPH 1, continued on para 2)

PARAGRAPH 2
look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose.

Any help, suggestion, or feedback would be deeply appreciated. Thanks in advance....
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of s_hausen
s_hausen

ASKER

hi agx,
one last thing..if i'm using # pound symbol or " double quote in my text its giving error. I tried, replace, replacelist and HTMLEditFormat functions but none of'em work, any clue???

<cfset stText = "It is a long established # fact that a reader will be "distracted" by the readable content of a page when looking at its layout. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for."/>
It's easier to use cfsavecontent instead of cfset. It captures all content as is. Then neither one is a problem.  

<cfsavecontent variable="stText">It is a long established # fact that a reader will be "distracted" by the readable content of a page when looking at its layout. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for.</cfsavecontent>

Just be aware cfsavecontent honors allspaces. So if you write it this way for readability, you'll need to use trim() to remove the leading and trailing white space

<cfsavecontent variable="stText">
It is a long established # fact that a reader will be "distracted" by the readable content of a page when looking at its layout. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for.
</cfsavecontent>

Open in new window


If you prefer to use <cfset> you'll have to escape them ie use 2 double quotes or 2 ##'s.  Kind of ugly, but that's what you have to do ;)

<cfset stText = "It is a long established ## fact that a reader will be ""distracted"" by the readable content of a page when looking at its layout. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for.">

Open in new window

i'm very impressed by this expert knowledge.