Why am I getting "object required" in the following? How can I remove the
period using trimend?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<% strAuthor = "abc." %>

</head>

<body>
<% response.write strauthor.trimend("."," ") %>
</body>
</html>

Re: trimend problem (remove trailing period) by McKirahan

McKirahan
Thu Jan 31 09:12:39 CST 2008

"RICK" <RICK@discussions.microsoft.com> wrote in message
news:41735784-7B31-47C6-B217-276A9F906FBA@microsoft.com...
> Why am I getting "object required" in the following? How can I remove the
> period using trimend?
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
>
> <% strAuthor = "abc." %>
>
> </head>
>
> <body>
> <% response.write strauthor.trimend("."," ") %>
> </body>
> </html>

Is "trimend()" a JavaScript function?

Are you trying to raplace the last character (as "trimend" implies),
in this case a period, with a space?

Do you want to replace all periods with a space: if so then:



Re: trimend problem (remove trailing period) by RICK

RICK
Thu Jan 31 09:20:04 CST 2008

I want to remove only the last period of a string.

"McKirahan" wrote:

> "RICK" <RICK@discussions.microsoft.com> wrote in message
> news:41735784-7B31-47C6-B217-276A9F906FBA@microsoft.com...
> > Why am I getting "object required" in the following? How can I remove the
> > period using trimend?
> >
> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> > <html>
> > <head>
> > <title>Untitled Document</title>
> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> >
> > <% strAuthor = "abc." %>
> >
> > </head>
> >
> > <body>
> > <% response.write strauthor.trimend("."," ") %>
> > </body>
> > </html>
>
> Is "trimend()" a JavaScript function?
>
> Are you trying to raplace the last character (as "trimend" implies),
> in this case a period, with a space?
>
> Do you want to replace all periods with a space: if so then:
>
>
>

Re: trimend problem (remove trailing period) by McKirahan

McKirahan
Thu Jan 31 09:24:32 CST 2008

"RICK" <RICK@discussions.microsoft.com> wrote in message
news:26524B2A-0571-4E33-95C2-6D8716BCC1E8@microsoft.com...
> I want to remove only the last period of a string.

[snip]

You're code suggested that you want to replace it with a space.

Will the period always be at the end of the string?





Re: trimend problem (remove trailing period) by RICK

RICK
Thu Jan 31 09:32:02 CST 2008

No, there may be periods within the string as well. I need to remove the
period at the end of the string if a period exists.



"McKirahan" wrote:

> "RICK" <RICK@discussions.microsoft.com> wrote in message
> news:26524B2A-0571-4E33-95C2-6D8716BCC1E8@microsoft.com...
> > I want to remove only the last period of a string.
>
> [snip]
>
> You're code suggested that you want to replace it with a space.
>
> Will the period always be at the end of the string?
>
>
>
>
>

Re: trimend problem (remove trailing period) by Bob

Bob
Thu Jan 31 09:38:55 CST 2008

RICK wrote:
> Why am I getting "object required" in the following?
Because:
1. unless you have changed the setting in IIS, the default server-side
scripting language is vbscript
2. you have not specified the server-side script language anywhere that
I can see so it should be defaulting to vbscript
3. you have a scalar variable (strauthor) that you are attempting to use
as if it was an object. Only objects have properties and methods. Unlike
javascript, in which everything is an object (yes, I know that's a
simplification), vbscript has scalar and object variables. Object
variables need to be initialized using the Set keyword. strauthor was
not initialized using Set, therefore you are getting the "object
required" error.

> How can I
> remove the period using trimend?

What is trimend? It's certainly not a builtin method that I have heard
of. The only reference to a TrimEnd method that I can find is in the
.Net documentation. Your code looks to me like classic (non-dotnet)
code, so either:
1. You have misread a book or some documentation somewhere that has led
you to believe that you could use a .Net method in classic ASP (you
can't), or
2. You have written a function called trimend that you have failed to
include in your page.

How to remove the period? There are many ways. Here is a non-regex one:

>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
function TrimEnd (s)
dim length
length = len(s)
if length > 0 then
if Right(s,1) = "." then
s= Mid(s,1,length - 1)
end if
TrimEnd = s
else
TrimEnd = s
end if
end function
%>
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
>
> <% strAuthor = "abc." %>
>
> </head>
>
> <body>
> <% response.write trimend(strauthor)%>
> </body>
> </html>



--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: trimend problem (remove trailing period) by McKirahan

McKirahan
Thu Jan 31 09:42:40 CST 2008

"RICK" <RICK@discussions.microsoft.com> wrote in message
news:B83B332A-7DE5-49A1-AF04-78C2BE1E3479@microsoft.com...
> No, there may be periods within the string as well. I need to remove the
> period at the end of the string if a period exists.

[snip]


Will this help?

<% Response.Write TrimLast(strAuthor,".") %>
<%
Function TrimLast(str,chr)
'****
'* Remove "chr" (if it exists) from end of "str".
'****
TrimLast = str
If Right(str,1) = chr Then TrimLast = Left(str,Len(str)-1)
End Function
%>