|
-
Aug 9th, 2006, 12:55 PM
#1
Thread Starter
Hyperactive Member
[2.0] Len Property???[RESOLVED]
From what i have seen in the msdn C# only contains a Len Property compared to VB.NET that has a boat load, for Len...Now this is fairly new Arena for me,dealing with Len and Char Strings...So here is the VB.NET Code section that i'm currently working on..
VB Code:
Public Function Header(ByVal PacketType As String, ByVal pck As String) As String
Dim i As Short
Dim x As Short
x = 0
i = Len(pck) /* Here is the Len part*/
Do While i > 255
i = i - 256
x = x + 1
Loop
Header = Name & Chr(0) & Chr(Ver) & New String(Chr(0), 2) & Chr(x) & Chr(i) & Chr(0) & Chr(CInt("&H" & PacketType)) & New String(Chr(0), 8) & pck
Debug.Print(Header)
End Function
Now i'm not even sure where to begin with the Len,because theirs hardly any information about it for C#..Only thing i have managed to find is a Len Property using a { get; set; }... Only other part of the Code above i havent moved to C# is the the section below::
VB Code:
Header = Name & Chr(0) & Chr(Ver) & New String(Chr(0), 2) & Chr(x) & Chr(i) & Chr(0) & Chr(CInt("&H" & PacketType)) & New String(Chr(0), 8) & pck
Thxs in Advance for the help on this quiet interesting section
Last edited by Rattlerr; Aug 9th, 2006 at 01:42 PM.
-
Aug 9th, 2006, 12:57 PM
#2
Re: [2.0] Len Property???
Won't this work?
i = pck.Length;
i would have to be declared as int though.
Edit: Removed brackets.
Last edited by sevenhalo; Aug 9th, 2006 at 01:00 PM.
-
Aug 9th, 2006, 01:07 PM
#3
Re: [2.0] Len Property???
VB Code:
Do While i > 255
i = i - 256
x = x + 1
Loop
What is the point of this. It's elementary maths, using a construct is just bloat
-
Aug 9th, 2006, 01:43 PM
#4
Thread Starter
Hyperactive Member
Re: [2.0] Len Property???[RESOLVED]
Thxs Sevenhalo that works out pretty good..
-
Aug 9th, 2006, 06:12 PM
#5
Re: [2.0] Len Property???[RESOLVED]
You're going about this the wrong way. Looking in C# documentation for information about Len (which is a function by the way, not a property) will get you nothing because it doesn't exist. You need to ask yourself "what does Len do?", and you would answer yourself "it gets the length of a string". As I posted in a previous thread, if you want to do something to a String object then chances are it will be done with a member of the String class. That means you should go to the MSDN documentation and read the member listing for the String class. I think that the Length property would jump out pretty quickly as the thing to use, and that's whether you're using C# or VB. It's a member of a class in the Framework class library, which means it can be used in any .NET language. You should follow these same steps for all VB Runtime functions. Ignore the function itself and just ask yourself what task you're trying to achieve and then find a way to achieve that task.
For the other section you should follow similar methodology. Ask yourself what you're trying to achieve. Firstly, you need to concatenate strings. That's done with the "+" operator in C#. Secondly, I already told you in a previous thread that null characters are represented with the '\0' escape sequence. Thirdly, you need to convert an integer to the Char it represents. That's should be done in VB or C# using the Convert.ToChar method. Fourthly, you need to create a hexadecimal string and convert that to a Char. The hex prefix in C# id "0x" and, again regardless of language, you should convert a hex string to an integer using Convert.ToInt32. This all leads you to:
Code:
header = name + '\0' + Convert.ToChar(ver) + "\0\0" + Convert.ToChar(x) + Convert.ToChar(i) + '\0' + Convert.ToChar(Convert.ToInt32("0x" + packetType, 16)) + "\0\0\0\0\0\0\0\0" + pck;
or better:
Code:
header = string.Format("{0}\0{1}\0\0{2}{3}\0{4}\0\0\0\0\0\0\0\0{5}",
name,
Convert.ToChar(ver),
Convert.ToChar(x),
Convert.ToChar(i),
Convert.ToChar(Convert.ToInt32("0x" + packetType, 16)),
pck);
-
Aug 9th, 2006, 06:15 PM
#6
Thread Starter
Hyperactive Member
Re: [2.0] Len Property???[RESOLVED]
Ok,I follow you on that...
-
Aug 10th, 2006, 12:53 AM
#7
Re: [2.0] Len Property???[RESOLVED]
I'm so sorry that my comment was "non-constructive" and didn't have a solution for you. I will remember not to try helping in future.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|