Saturday, March 31, 2012

String String Function

All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that
are available in ASP are supported by ASP.NET as well except for the
string function 'String'.
The 'String' function takes this form:
String(number, character)
which returns a string consisting of *character* which is repeated
*number* times. For e.g.
String(3, "$")
would return
$$$
or
String(5, "A")
would return
AAAAA
But when I try to use this function in ASP.NET, the following error
gets generated
'String' is a class type and cannot be used as an expression.
It's pretty obvious what makes ASP.NET generate the above error but
how do I make use of this 'String' function in ASP.NET? Is there any
equivalent string function in ASP.NET?
Actually my main intention is to replace the first 10 characters of a
text with dots irrespective of the no. of characters in the text (or
the 'Len' of the text) which is why I needed to use the 'String'
function. Had ASP.NET supported the 'String' function, then the
following would have served my purpose:
strText = "The quick brown fox jumps over the lazy dog."
strText = String(10, ".") & Mid(strText, 11, Len(strText))
I can't use the 'Replace' function since the first 10 characters (or,
for that matter, the entire text) can be a combination any characters
(even non-alphanumeric).string str = new string(' ', 10);
<rn5a@.rediffmail.com> wrote in message
news:1170864460.723705.243170@.k78g2000cwa.googlegroups.com...
> All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that
> are available in ASP are supported by ASP.NET as well except for the
> string function 'String'.
> The 'String' function takes this form:
> String(number, character)
> which returns a string consisting of *character* which is repeated
> *number* times. For e.g.
> String(3, "$")
> would return
> $$$
> or
> String(5, "A")
> would return
> AAAAA
> But when I try to use this function in ASP.NET, the following error
> gets generated
> 'String' is a class type and cannot be used as an expression.
> It's pretty obvious what makes ASP.NET generate the above error but
> how do I make use of this 'String' function in ASP.NET? Is there any
> equivalent string function in ASP.NET?
> Actually my main intention is to replace the first 10 characters of a
> text with dots irrespective of the no. of characters in the text (or
> the 'Len' of the text) which is why I needed to use the 'String'
> function. Had ASP.NET supported the 'String' function, then the
> following would have served my purpose:
> strText = "The quick brown fox jumps over the lazy dog."
> strText = String(10, ".") & Mid(strText, 11, Len(strText))
> I can't use the 'Replace' function since the first 10 characters (or,
> for that matter, the entire text) can be a combination any characters
> (even non-alphanumeric).
>
On Feb 7, 9:17 pm, "Aidy" <a...@.noemail.xxxa.com> wrote:
> string str = new string(' ', 10);
> <r...@.rediffmail.com> wrote in message
> news:1170864460.723705.243170@.k78g2000cwa.googlegroups.com...
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -
Thanks a lot, Aidy :-)

0 comments:

Post a Comment