(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
09-21-24 09:28 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - VB6 Halving strings
  
User name:
Password:
Reply:
 
Options: - -
Quik-Attach:
Preview for more options

Max size 1.00 MB, types: png, gif, jpg, txt, zip, rar, tar, gz, 7z, ace, mp3, ogg, mid, ips, bz2, lzh, psd

UserPost
Sukasa
Posts: 778/2068
Here, I placed kawa's code into a function for you to use.


Public Function Halve(input As String)
' This function returns a string array. to use, dimension a dynamic string array, i.e.
' Aim array() as string.
' Then
' array = Halve("string")

' This will return array(0) = "str", array(1) = "ing".


' Declare variables
dim internalarray(1) As String, internala as integer

' Find missle point.
internala = (Len(input) - (Len(input) Mod 2)) / 2

' Split the input string
internalarray(0) = left(input, internala)
internalarray(1) = Right(input, Len(input) - internala)

' And return the new data.
Halve = internalarray
End Function


That should work for you.
Kyoufu Kawa
Posts: 648/1353
...but either way, to split using VB6's indeed (and I too think they could be better), use...

firstHalf = Left(fullString, Len(fullString) / 2)
secondHalf = Right(fullString, Len(fullString / 2)

Might need a +1 or -1 somewhere.
Parasyte +
Posts: 46/53
If this is for splitting hexadecimal bytes into nybbles, as it appears to be, you are better off using math:

results(1) = number / 16
results(2) = number Mod 16
Dan
Posts: 113/219
The functions you are looking for are the Left function, the Right function, and probably also the Len function.

I'd actually forgotten how poor VB's string support actually is.
dcahrakos
Posts: 346/499
I know you can use the split function to split strings into an array, but im not sure if you can use split to actually half the string without some delimiter, such as a space, or any other letter or symbol right at the halfway point of the string...so if you did want it like that you could do:

dim arry() as string
arry = Split (strng, " "), but that will split the string at every space, you can change the delimiter to whatever, but I dont think split can do halves, ill look for a specific function for you though.
Arthus
Posts: 54/142
I can't seem to locate a function that can let me half a string. When I tried to make one, I couldn't find anything that would remotly help me in doing so. So does anyone have a function that would let me turn a string into an array.

Example:
String = "AE"

after putting this string through the function:
hlaf("AE")

the array would come as follows:
results = Array(
1 => "A"
2 => "E"
)

Or something along those lines.
Acmlm's Board - I3 Archive - Programming - VB6 Halving strings


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.004 seconds; used 349.96 kB (max 389.74 kB)