• Welcome to Valhalla Legends Archive.
 

another quick question

Started by gotcha_ass, February 25, 2003, 07:30 PM

Previous topic - Next topic

gotcha_ass

Ok I need to extract the strings out of the packetdata
The strings start at position 25, and go to the end of the string. How would I write the syntax to make Mid start at 25 and goto the end of the string?
So far I have:

StringData = Mid(PacketData, 25, End_of_String)

What do I need to replace End_of_String with?

l)ragon

#1
QuoteOk I need to extract the strings out of the packetdata
The strings start at position 25, and go to the end of the string. How would I write the syntax to make Mid start at 25 and goto the end of the string?
So far I have:

StringData = Mid(PacketData, 25, End_of_String)

What do I need to replace End_of_String with?


StringData = Mid(PacketData, 25, len(PacketData))

*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*

Grok

#2
QuoteStringData = Mid(PacketData, 25, len(PacketData))

 

When using Mid() to read from start to end-of-data,

StringData = Mid(PacketData, 25, len(PacketData) - 24)
or just
StringData = Mid(PacketData, 25)

are both acceptable forms.

gotcha_ass

#3
thanx soo much

Banana fanna fo fanna

#4
stringData = right(packetData, len(packetData)-25)

Camel

#5
QuotestringData = right(packetData, len(packetData)-25)
mid(packetdata, 25) is easier to read :)

Grok

#6
QuotestringData = right(packetData, len(packetData)-25)

stringData = right(packetData, len(packetData)-24)


Mesiah / haiseM

#7
yes it would be len() - 24 because if your starting at the 25 char, then you need to add one more char to it, so if you did len() - 25 then you would go back to an unwanted char.
]HighBrow Innovations
Coming soon...

AIM Online Status: 

Camel

Quoteyes it would be len() - 24 because if your starting at the 25 char, then you need to add one more char to it, so if you did len() - 25 then you would go back to an unwanted char.
right, it's due to one of the things that, believe it or not, was intended to make vb n00b-friendly. in c, you might use "&buffer[24]" or "buffer+24" (obviously, buffer being a pointer to a char array). in vb the first charactor is 1 not zero, so you have to add 1. very annoying to count "multiple of four plus one"s.
imho, microsoft should have included at least minimal support for pointers. yes, there are undocumented functions such as strptr,varptr, and there is addressof, but just TRY and use them without crashing vb. you can also combine CopyMemory with ByRef/ByVal (ByRef = &; ByVal = *) to put a pointer in to a long, or turn a pointer in to data. but then, what if you have a string pointer? you need to grab ONE byte at a time and stop at the first NULL so you don't go beyond whatever allocated memory there is.
as long as i'm ranting about vb, what's up with all the signed variables!? i mean seriously...signed boolean? give me a fucking break.

[edit]oh yeah, and another thing
i'm surprised nobody, to my knowledge, has figgured out (and published) that you can use vb's types to outline your shit...you dont even need to do net short/long to host conversion in vb.
example:

type packetheader
    the0xFFthing as byte
    id as byte
    length as integer
    data as string
end type

sub sck_dataarrival()
    dim ph as packetheader
    sck.peekdata ph, 4        'peek at the header up to packet length
    sck.getdata ph, ph.length 'now really get it
    parsebinary ph
end sub

sub parsebinary(packet as packetheader)
  //code...
end sub

i actually discovored this before i knew the first thing about c structs. i was writing a server clone for hotline a couple years ago, and it had a 64bit list of privs that it used for each account. rather than trying to bust out each one individually, i made a type, and threw 64 "dim privname as boolean"s in it. after that, just a copymemory from the string to the type, and i was all set. ;)

Banana fanna fo fanna

#9
Dude that is HOT.

Grok

#10
Quotei actually discovored this before i knew the first thing about c structs. i was writing a server clone for hotline a couple years ago, and it had a 64bit list of privs that it used for each account. rather than trying to bust out each one individually, i made a type, and threw 64 "dim privname as boolean"s in it. after that, just a copymemory from the string to the type, and i was all set. ;)

No you didn't.  VB Booleans are 16-bit.

Camel

#11
err, sorry. i did 4 bytes. it was a long time ago, leave me alone ;)

gotcha_ass

#12
Wohoo I did it ;D

StringData = Mid(PacketData, 25) 'remove only strings
Dim i As String
i = InStr(StringData, vbCrLf) 'find position of first vbcrlf
IX86verFileName = Mid(StringData, 1, i) 'Now holds the first NTString
ValueString = Mid(StringData, i + 1) 'How holds second NTString
            
'Dont forget to remove the VbCrLfs

How do I trim the VbCrLf off the end of the strings?

Grok

#13
Dim strLineArray() As String
strLineArray = Split(StringData, vbCrlf)

Now you have a 0-based array containing each line.

gotcha_ass

#14
QuoteDim strLineArray() As String
strLineArray = Split(StringData, vbCrlf)

Now you have a 0-based array containing each line.



That can replace my code?? Would be a lot easier that way. Does it keep the vbCrlf at the end of each string or throw it away?