Forums

ASP

This topic is locked

Crop Sentance from Recordset ASP Javascript

Posted 30 Dec 2005 00:08:35
1
has voted
30 Dec 2005 00:08:35 Gareth Tannatt Nash posted:
Hi there,

does anyone know how to crop a sentance from a recordset on an ASP Javascript page? i've seen an extension that does this on ASP VB pages, but nothing for Javascript?
Your thoughs would be appreciated
Thanks

Replies

Replied 09 Jan 2006 17:35:06
09 Jan 2006 17:35:06 Lee Diggins replied:
Hi Gareth

You can use the slice method:

<%
var myValue = "I was once a boy, now I'm a man";
Response.Write(myValue + "<br>"
Response.Write(myValue.slice(2) + "<br>"
Response.Write(myValue.slice(2, 10) + "<br>"
Response.Write(myValue.slice(5, 12) + "<br>"
Response.Write(myValue.slice(0, 10) + "<br>"
%>

Just change the myValue to point to your rs.value

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 10 Jan 2006 11:01:14
10 Jan 2006 11:01:14 Lee Diggins replied:
Hi Gareth

Should have included some info on the slice method as well:

slice Method (String)

See Also
Array Object | slice Method (Array) | String Object Methods

Applies To: String Object
Requirements
Version 3
Returns a section of a string.

stringObj.slice(start, [end])

<b>Arguments</b>
<b>stringObj </b>Required. A String object or literal.
<b>start </b>Required. The index to the beginning of the specified portion of stringObj.
<b>end </b>Optional. The index to the end of the specified portion of stringObj.

<b>Remarks</b>
The slice method returns a String object containing the specified portion of stringObj.

The slice method copies up to, but not including, the element indicated by end. If start is negative, it is treated as length + start where length is the length of the string. If end is negative, it is treated as length + end where length is the length of the string. If end is omitted, extraction continues to the end of stringObj. If end occurs before start, no characters are copied to the new string.

<b>Example</b>
In the following example, the two uses of the slice method return the same result. In the second example, negative one (-1) points to the last character in str1 as the ending point.

str1.slice(0)
str2.slice(0,-1)

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic