Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

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 :-)

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 :-)

String to integer conversion

Hello!

Class int has a method for conversion numeric values to strings (ToString() method). Is there any similar method or function, which converts a string into Int32 type?

Cheers!static method System.Int32.Parse()
Thanks!
Hello!

I tried to use the method you gave me, but got an error message: "System.FormatException: Input string was not in a correct format."
Maybe there is any special way I should use it?

Here's how I do it:


void Fill_End_Day(int auto, int aasta, int kuu, int paev) {
autorent.broneering wsProxy = new autorent.broneering();
System.Data.DataSet ds;
ds = wsProxy.JargmineHyiv(auto, aasta, kuu, paev);
int i;
for (i=paev; i<System.Int32.Parse(ds.Tables[0].Rows[0]["paev"].ToString()); i++)
DropDownList7.Items.Add(i.ToString());
}

Is there something wrong with it?

Cheers.
c# doesn't have cInt()?
I'm afraid it doesn't. Maybe there is some similar function, but I can't even assume in which class I should seek for it.
Sorry, it works now! It should have worked from the beginning, but there has been a stupid mistake in another palce.
Thank you!

string to object

Hi

How to convert string to object?

i.e.

string objname = "Control1"

then some how use (function or method)

objname.visible = false

Hi There,

asmgx:

How to convert string to object?

i.e.

string objname = "Control1"

then some how use (function or method)

objname.visible = false

You can assign string value to object

e.g

string value = "control1";

object obj = value;

But not using string value to identify as object.

However, you can use string value as id and find the control.

e.g

Say you wanted to get textbox with id myTextBox

TextBox txt = (TextBox)this.FindControl("myTextBox"); //


in c#

String obj ="Control1";

Object objCast = ((Object)obj);

in vb

Dim objAsString = "Control1"

Dim objCastAsObject = (CType(obj,Object))

asmgx:

then some how use (function or method)

objname.visible = false

what exact you want to do?

Wednesday, March 28, 2012

string.equals general question

hi

there's something with the following I just can't seem to understand.

Private Function stringequals() As String

Dim str1 As String = "aaa"
Dim str2 As String = "bbb"
Dim str3 As String = "ccc"
Dim str4 As String = "aaa"

str1 &= str1.Equals(str2, str3)

Return str1

End Function

This function returns the string 'aaaFalse', as I was expecting. What I dont understadn is this;

The Equals method is overloaded so that I can compare two objects, as I'm doing here with str2 and str3. I can't see why they've done this. str2 and str3 have NOTHING to do with str1.

I'd understand if the line was;

str1 &= str1.Equals(str4)

Of course, this is a valid overload method too.

I'm only really asking my question because I'm new to vb.net and OO in general. The str1.Equals method is 'part' of str1, but compares two different obects (str2 and str3). This doesnt make sense to me.

any thoughts?

thanks

mauriceI think that two things are throwing you.

First, you have used the &= operator which means, "add to" ...

str1 &= str2 means"aaa" + "bbb" and will give you"aaabbb"
str1 &= False means"aaa" + "False" and will give you"aaaFalse"

The last example is why you are getting "aaa" in your result.

The second thing I think is throwing you is what, exactly, the.Equals is doing. It compares the thing before .Equals to the thing in the brackets.

If there is only one thing in the brackets, then it works simply:
str1.Equals("aaa") asks whether"aaa" = "aaa" and the answer isTrue
str1.Equals(str2) asks whether"aaa" = "bbb" and the answer isFalse

But, if there are two things in the brackets, it compares all three things (this is notstrictly true, but it's true enough with the example you've provided):
str1.Equals("aaa", str4) asks whether"aaa" = "aaa" = "aaa" and the answer isTrue
str1.Equals(str3, str4) asks whether"aaa" = "ccc" = "aaa" and the answer isFalse

So, your expressionstr1 &= str1.Equals(str2, str3") is working like this:

str1.Equals(str2, str3") asks whether"aaa" = "bbb" = "ccc" which isFalse.

So, your expression reduces tostr1 &= False.

Remember that the &= operator means to add the second thing to the first, so:
str1 &= False means"aaa" + "False" which becomes"aaaFalse"

Has that helped explain what, exactly, is going on?
Actually, not true.

str1.Equals(str2,str3) compares ONLY str2 and str3.

While this implementation might seem a tad confusing, this is only from the perspective you are using it here.

.Equals is implemented as a shared method, so you don't need to instantiate the string object to use it. For example:

blnStringComp = String.Equals(str2,str3)

You might use it in this fashion to compare, say, the content of two textboxes, without creating an explicit instance of the string class to do so:

blnStringCompare = String.Equals(Me.txt1.Text, Me.txt2.Text)

Is it a bit superfluous? Perhaps. I think a better question is (and I ask this seriously), is String.Equals faster than just using the "=" operator.
I said that my explanation wasn't strictly true ... but, you're right, it's not even "almost true" :)

You're also right ... simply using a set of "=" operator tests would be easier. However, I think that String.Equals is probably faster over a number of boolean tests, in the same way that the StringBuilder class is faster than "&=" for more than handful of string concatenations.
thanks for your answers, i thought something 'strange' was going on...

"Equals is implemented as a shared method, so you don't need to instantiate the string object to use it. For example:

blnStringComp = String.Equals(str2,str3)"

now it all makes sense, mostly ;)
An intresting aside

In a (good?) OO language like C# the above wont compile, and thus remove the potential misunderstsanding of what is happening.

One can't call static (shared) members on an instance of a class, only on the type.

Another gotcha, the object.equals(obj1, obj2) will only do a reference equals, ie are the objects the same (ie the same address), not a value equals, do the objects have the same value. The string.equals(string1, string2) will do a value equals. I imagine this is what is called in the above instances.

M G Walmsley
Thatwas interesting.

You mentioned that .Equals tests references, not values. You then explain that the reference test asks "are the objects the same (ie the same address)". By "the same address", do you mean the "address" as used inAddHandler btnSend.Click, AddressOf btnSend_Click? If so, it means I've misunderstood the difference between ByVal and ByRef...
By address i mean the address in memory of the object. Normally this is not available or needed in code, but can be got at if needed. This is returned by AddressOf, though strictly this is a function delegate, ie the address and signature of the function.

By Ref means that the address (as above) is passed to the function. So code inside the called function will update the object in the callee.

For Reference objects, eg, classes, this is the normal way to pass them to functions.
Value types, primitives, ints etc, and structures are normally passed By Value not By Ref.

By Value means the value of the object is passed. IF an object is passed by value, it is copied to a new object. This means the object in the callee will not be updated in the called function.
Another thing to be carefull about.

All types derive from object. Object has a Equals method that works as described (a reference equals).

So all types have a Equals method. So unless they are overridden be a derived type, the base object.Equals will be called.

String does have an override of Equals which does a value equals, but only if called with two strings.

The thing to always be aware of when one writes a statement like xxx.Equals(aaa, bbb) is what will actually be called.
Thanks, mgwalm, for your explanation.

For this cowboy (self-taught) developer, it shows how much I don't know about the very fundamentals of programming :/

String.Formatting a javascript code sample, how do I escape the { } characters?

Hi,

I'm trying to String.format a piece of javascript code

string.Format("function showalert(msg) { window.status = '{0}'; alert(msg); }", "Test");

This compiles ok but when it runs it has a Input string was not in a correct format exception as the '{' and '}' characters are reserved and used for substitution in the string.Format function.

Is there a way I can escape the '{}' characters so that the string.format function ignores them?

I've tried

string.Format("function showalert(msg) \{ window.status = '{0}'; alert(msg); \}", "Test");

which is normally how you escape but it dosen't work.

Thanks for your help

Auschucky

Hi ,To specify a single literal brace character informat, specify two leading or trailing brace characters; that is, "{{" or "}}".
string test =string.Format("function showalert(msg) {{ window.status = '{0}'; alert(msg); }}","Test");
Hope this helps , Gook Luck^_^
Ta, worked a treat

string.indexof case insensitive

Sir,
To my experience, the string.indexof function is case sensitive. I need it
to be case insensitive, how should I achieve this?
Kind regards
Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.comUse toLower() on all strings concerned.
"Guoqi Zheng" <no@.sorry.nl> wrote in message
news:ezCrd2YZEHA.524@.TK2MSFTNGP09.phx.gbl...
> Sir,
> To my experience, the string.indexof function is case sensitive. I need it
> to be case insensitive, how should I achieve this?
> --
> Kind regards
> Guoqi Zheng
> guoqi AT meetholland dot com
> Http://www.meetholland.com
>
>
Have you tried looking into IndexOfAny and passing both the upper case and
lower case character?
Hope this helps.
"Guoqi Zheng" <no@.sorry.nl> wrote in message
news:ezCrd2YZEHA.524@.TK2MSFTNGP09.phx.gbl...
> Sir,
> To my experience, the string.indexof function is case sensitive. I need it
> to be case insensitive, how should I achieve this?
> --
> Kind regards
> Guoqi Zheng
> guoqi AT meetholland dot com
> Http://www.meetholland.com
>
>
wait!.. User string.ToUpper() instead...
Just kidding!.
Dale
"Josh" <someone@.microsoft.com> wrote in message
news:e4vyMpZZEHA.4032@.TK2MSFTNGP11.phx.gbl...
> Use toLower() on all strings concerned.
> "Guoqi Zheng" <no@.sorry.nl> wrote in message
> news:ezCrd2YZEHA.524@.TK2MSFTNGP09.phx.gbl...
it
>

string.indexof case insensitive

Sir,

To my experience, the string.indexof function is case sensitive. I need it
to be case insensitive, how should I achieve this?

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.comUse toLower() on all strings concerned.

"Guoqi Zheng" <no@.sorry.nl> wrote in message
news:ezCrd2YZEHA.524@.TK2MSFTNGP09.phx.gbl...
> Sir,
> To my experience, the string.indexof function is case sensitive. I need it
> to be case insensitive, how should I achieve this?
> --
> Kind regards
> Guoqi Zheng
> guoqi AT meetholland dot com
> Http://www.meetholland.com
Have you tried looking into IndexOfAny and passing both the upper case and
lower case character?

Hope this helps.

"Guoqi Zheng" <no@.sorry.nl> wrote in message
news:ezCrd2YZEHA.524@.TK2MSFTNGP09.phx.gbl...
> Sir,
> To my experience, the string.indexof function is case sensitive. I need it
> to be case insensitive, how should I achieve this?
> --
> Kind regards
> Guoqi Zheng
> guoqi AT meetholland dot com
> Http://www.meetholland.com
wait!.. User string.ToUpper() instead...

Just kidding!.

Dale

"Josh" <someone@.microsoft.com> wrote in message
news:e4vyMpZZEHA.4032@.TK2MSFTNGP11.phx.gbl...
> Use toLower() on all strings concerned.
> "Guoqi Zheng" <no@.sorry.nl> wrote in message
> news:ezCrd2YZEHA.524@.TK2MSFTNGP09.phx.gbl...
> > Sir,
> > To my experience, the string.indexof function is case sensitive. I need
it
> > to be case insensitive, how should I achieve this?
> > --
> > Kind regards
> > Guoqi Zheng
> > guoqi AT meetholland dot com
> > Http://www.meetholland.com

Monday, March 26, 2012

stringbuilder question

i am calling the function "ClientInfo" from a repeater. i.e.


<itemtemplate>
<%# ClientInfo(((IDataRecord)Container.DataItem)["CLIENTCODE"].ToString())%>
</itemtemplate>

i am using stringbuilder within my function for the first time. it is working but i just wanted to make sure i am using the stringbuilder correctly. in particular, are my last 2 lines ok i.e. do i have to convert the stringbuilder back to a string in order to return the final HTML output? thanks


public string ClientInfo(string clientCode)
if (clientCode == previousclientCode)
{
System.Text.StringBuilder clientInfoStr = new System.Text.StringBuilder();
clientInfoStr.Append("<table width='100%' border='0'>");
clientInfoStr.Append("<tr class='searchresrow1'>" + SRreader.GetString(3) + "</td>");
string clientInfo = clientInfoStr.ToString();
return clientInfo;
}
else ...
In your case StringBuilder is useless, because you don't concatinate much.
I suggest you to use string.format instead of stringbuilder

For example:
<code>
string ClientInfoStr = @."
<table width='100%' border='0'>
<tr class='searchresrow1'>{0}</td>";
return string.Format(ClientInfoStr, SRreader.GetString(3));

Much simpler and faster.
HTH
sorry - i am in fact returning a long string but i cut it down to 2 lines on my post so people wouldnt get put off!

string clientInfo = clientInfoStr.ToString();

return clientInfo;

could just as well be:


return clientInfoStr.ToString();

This would save the extra String var declaration on clientInfo.

JD

StringCollection

Hi

I got this function in C#:


internal string JoinStringCollection(StringCollection SC)
{
string[] ToListArray = new string[SC.Count];
SC.CopyTo(ToListArray,0);
return string.Join("; ",ToListArray);
}

I converted it as follows, but cant seem to get the right syntax:


Friend Function JoinStringCollection(ByVal SC As StringCollection) As String

Dim ToListArray() As String = New String(SC.Count) 'This generates error, expects char?
SC.CopyTo(ToListArray, 0)
Return String.Join("; ", ToListArray)
End Function

Add "{}" at the end of the "New" statement

AutoFed
Try this:
Dim ToListArray(SC.Count) As String

strings

Pls help me write a function in c#, to exclude all the dots(.) from a string.
Like the string "123.0000" should return "1230000"
Thanks a ton.Use the Replace function or regular expressions
Thanks...

Saturday, March 24, 2012

Strings, webformatting

Hey.

I believe when I was reading through unleashed, I saw a function that converts strings to a nice webform and back again, but I can't remember, and I can't find it again, LOL...

Basically,

What I want to do:

I email users a web address containing their email and validation code

example:

http://mySite.com/verify.aspx?User=<user name>&Code=<code
now this is working awesome, except, if the username had a space in it, the system falls down (as the link stops where the space is)

so basically, I wanna know if there is a function I can run on the string containing the web address that will convert the spaces to %20, and if there is a function that converts it back again (%20's to a space).

I'm sure I could code my own function and put it in a namespace or something, but it'd be so much nicer if there was a default function (YAY)

is there? or am I stark raving mad?!?! lol

Thanks for your help
-AshleighHi Ashleigh

Perhaps the "Server.URLEncode" and "Server.UrlDecode" will help you.

Thursday, March 22, 2012

Structure Data Type

If I want to pass a structure data type to a function then what data type is it? Object? Or is it just a bad thing to pass structs?

Thanks,
TreyA struct type is a "value type" so it is not an object ( reference type ).

Sam
so say i have a sub like:


sub insertX( byVal someValue as ___________)

end sub

What goes in the ___________ part.

Thanks,
Trey
You would pass it the name of the struct you created. Say you create a struct called Employee, here is how you would pass it:

sub insertX( byVal someValue as Employee a)

//Do stuff with a

end sub

Sam
The ____ will be the structure type:

<%@. Page Language="VB" %>
<html>
<head>
<script runat="server">
Structure Favourite
Public Colour As String
Public Number As Integer
End Structure

Sub Page_Load(sender As Object, e As EventArgs)
Dim MyFavourite As New Favourite
MyFavourite.Colour = "black"
Myfavourite.Number = "10"
Report( MyFavourite )
End Sub

Sub Report( ThisFavourite As Favourite )
Message.Text = "Your favourite colour is " & ThisFavourite.Colour
Message.Text &= ", and your favourite number is " & ThisFavourite.Number.ToString()
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:Label id="Message" runat="server" />
</form>
</body>
</html>


thanks....that helped me figure out what i was doing wrong.

Trey

Tuesday, March 13, 2012

stuck in a loop

Hi

I try to use this piece of code, but the page seems to get stuck in the loop. What am I doing wrong here?

Function NumberOfLinesInFile()
Dim path As String = Server.MapPath("row.txt")
Dim sr As StreamReader = New StreamReader(path)
Dim i As Integer
i = 0
Do While sr.Peek() >= 0
i = i + 1
Loop
sr.Close()
Return i
End Function

Regards

Mhello, what if sr.Peek() is always >= 0 ? check the values returned by sr !!!
The Peek function does not move to the next character, it only consumes it. Try using the sr.Read() instead.

hope this helps,

sivilian