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@dotnet.itags.org.rediffmail.comwrote in message
news:1170864460.723705.243170@dotnet.itags.org.k78g2000cwa.googlegr oups.com...

Quote:

Originally Posted by

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...@dotnet.itags.org.noemail.xxxa.comwrote:

Quote:

Originally Posted by

string str = new string(' ', 10);
>
<r...@dotnet.itags.org.rediffmail.comwrote in message
>
news:1170864460.723705.243170@dotnet.itags.org.k78g2000cwa.googlegr oups.com...
>
>
>

Quote:

Originally Posted by

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'.


>

Quote:

Originally Posted by

The 'String' function takes this form:


>

Quote:

Originally Posted by

String(number, character)


>

Quote:

Originally Posted by

which returns a string consisting of *character* which is repeated
*number* times. For e.g.


>

Quote:

Originally Posted by

String(3, "$")


>

Quote:

Originally Posted by

would return


>

Quote:

Originally Posted by

$$$


>

Quote:

Originally Posted by

or


>

Quote:

Originally Posted by

String(5, "A")


>

Quote:

Originally Posted by

would return


>

Quote:

Originally Posted by

AAAAA


>

Quote:

Originally Posted by

But when I try to use this function in ASP.NET, the following error
gets generated


>

Quote:

Originally Posted by

'String' is a class type and cannot be used as an expression.


>

Quote:

Originally Posted by

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?


>

Quote:

Originally Posted by

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:


>

Quote:

Originally Posted by

strText = "The quick brown fox jumps over the lazy dog."
strText = String(10, ".") & Mid(strText, 11, Len(strText))


>

Quote:

Originally Posted by

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).- Hide quoted text -


>
- Show quoted text -


Thanks a lot, Aidy :-)

0 comments:

Post a Comment