Between Function?

Discussion in 'Programming General' started by AB, Apr 22, 2007.

Between Function?
  1. Unread #1 - Apr 22, 2007 at 10:19 PM
  2. AB
    Joined:
    Dec 19, 2005
    Posts:
    141
    Referrals:
    4
    Sythe Gold:
    15

    AB Active Member

    Between Function?

    Can some one please post how to get a between function.

    Thanks

    AB
     
  3. Unread #2 - Apr 23, 2007 at 9:27 AM
  4. dodge
    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5

    dodge Active Member
    Banned

    Between Function?

    sry i don’t get this question, can you explain more please?
     
  5. Unread #3 - Apr 24, 2007 at 11:43 PM
  6. AB
    Joined:
    Dec 19, 2005
    Posts:
    141
    Referrals:
    4
    Sythe Gold:
    15

    AB Active Member

    Between Function?

    well, i am making a program that loads information from a .txt or a .dat file, the file has more than 1 thing that it needs to retrieve.

    This is the file:
    Code:
    andrew.posx: 100;
    andrew.posy: 100;
    how do i get the posx and posy into a string?

    like do i use a between function like delphi and scar?
    i.e.
    Code:
    string = "andrew.posx: 100;"
    posx = between("andrew.posx: ",";",string)
     
  7. Unread #4 - Apr 25, 2007 at 8:16 AM
  8. speljohan
    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0

    speljohan Guru
    Visual Basic Programmers

    Between Function?

    why not just use it this way:
    Code:
    Dim theString As String
    Dim tmp() As String
    theString = "andrew.posx: 100;"
    tmp = Split(string, ":")
    tmp = Split(tmp(1), ";")
    posx = tmp(0)
    Or you could write your own between function. If i have some time over today i'll write one.
     
  9. Unread #5 - Apr 25, 2007 at 9:26 AM
  10. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Between Function?

    well this is probly a shit between function but meh, i tried:
    Code:
    public function findstring(strstring as string, del1 as string, del2 as string) as string
        on error goto error
        findstring = split(strstring,del1)(1)
        findstring = split(findstring,del2)(0)
        trim(findstring)
        exit function
    error:
        msgbox "an error has occurred." & vbcrlf & vbcrlf & "error number: " & err.number & vbcrlf & "error description: " & err.description",vbcritical, "findstring error"
    end function
    example of how to use it:
    Code:
    dim example as string
    example = "pos x : 100;"
    msgbox findstring example, ":", ";"
    the msgbox should display "100"
     
  11. Unread #6 - Apr 25, 2007 at 9:37 AM
  12. dodge
    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5

    dodge Active Member
    Banned

    Between Function?

    if the file has a regular pattern you can always use regex, it will be a lot easy and way faster on large files
     
  13. Unread #7 - Apr 25, 2007 at 10:56 AM
  14. speljohan
    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0

    speljohan Guru
    Visual Basic Programmers

    Between Function?

    or you could simply use XML files which would make it ALOT cleaner. It would simplify reading alot too.
     
  15. Unread #8 - Apr 26, 2007 at 4:57 AM
  16. AB
    Joined:
    Dec 19, 2005
    Posts:
    141
    Referrals:
    4
    Sythe Gold:
    15

    AB Active Member

    Between Function?

    thanks, just what i needed :)
     
  17. Unread #9 - Apr 26, 2007 at 8:41 AM
  18. dodge
    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5

    dodge Active Member
    Banned

    Between Function?

    this will be a lot easier

    Code:
    Dim SubjectString as String = "pos x : 100;"
    Dim ResultString As String =Regex.Match(SubjectString, ":(.*);").Groups(1).Value.Trim
    btw


    i dont think this is .net
     
  19. Unread #10 - Apr 26, 2007 at 8:44 AM
  20. speljohan
    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0

    speljohan Guru
    Visual Basic Programmers

    Between Function?

    o_O very nice function there dodge. I didn't think you could use regexes that way.
     
  21. Unread #11 - Apr 26, 2007 at 8:51 AM
  22. dodge
    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5

    dodge Active Member
    Banned

    Between Function?

    dunno what you mean, just type this on form and test it ot works for me

    Code:
    Imports system.Text.RegularExpressions
    
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim SubjectString As String = "pos x : 100;"
            Dim ResultString As String = Regex.Match(SubjectString, ":(.*);").Groups(1).Value.Trim
            MessageBox.Show(ResultString)
        End Sub
    End Class 
    
    btw i just changed to get the value from the groups just i can take the value i want, instaead of the full match
     
  23. Unread #12 - Apr 26, 2007 at 9:36 AM
  24. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Between Function?

    looks at regex, *passes out*
     
  25. Unread #13 - Apr 26, 2007 at 10:20 AM
  26. dodge
    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5

    dodge Active Member
    Banned

    Between Function?

    lol i dunno man you both lost me at hello ;),

    nvm me i'm just a bit stoned this morning!
     
  27. Unread #14 - Apr 26, 2007 at 10:58 AM
  28. speljohan
    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0

    speljohan Guru
    Visual Basic Programmers

    Between Function?

    uh, he's not saying your code is bad. He's saying he doesn't understand it :) Which means you are a good programmer, which is good :D
     
  29. Unread #15 - Apr 26, 2007 at 11:08 AM
  30. Cheeter
    Joined:
    Jun 5, 2005
    Posts:
    3,851
    Referrals:
    1
    Sythe Gold:
    31
    Discord Unique ID:
    236215891849641985
    Discord Username:
    Charkel#8050
    Extreme Homosex Homosex

    Cheeter Grand Master
    Cheetah Retired Global Moderator

    Between Function?

    *Sigh* Covey's a noob :p
     
  31. Unread #16 - Apr 30, 2007 at 10:41 AM
  32. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Between Function?

    lol speljohan tried to explain regex's to me ages ago over msn, i just kept saying "yep" as if i understood what he was talking about :p

    although to my understanding i should start learning it considering how effective it seems to be :)
     
  33. Unread #17 - Apr 30, 2007 at 3:10 PM
  34. dodge
    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5

    dodge Active Member
    Banned

    Between Function?

    try this program out
    http://www.regexbuddy.com/

    i'm sure u can find it on emule or somthing as well, its very helpfull when working with regular expressions
     
< [Question]Dnload VB.NET Location? | Help about c++. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site