Adblock breaks this site

Between Function?

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

  1. AB

    AB Active Member

    Joined:
    Dec 19, 2005
    Posts:
    141
    Referrals:
    4
    Sythe Gold:
    15
    Between Function?

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

    Thanks

    AB
     
  2. dodge

    dodge Active Member
    Banned

    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5
    Between Function?

    sry i don’t get this question, can you explain more please?
     
  3. AB

    AB Active Member

    Joined:
    Dec 19, 2005
    Posts:
    141
    Referrals:
    4
    Sythe Gold:
    15
    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)
     
  4. speljohan

    speljohan Guru
    Visual Basic Programmers

    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0
    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.
     
  5. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    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"
     
  6. dodge

    dodge Active Member
    Banned

    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5
    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
     
  7. speljohan

    speljohan Guru
    Visual Basic Programmers

    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0
    Between Function?

    or you could simply use XML files which would make it ALOT cleaner. It would simplify reading alot too.
     
  8. AB

    AB Active Member

    Joined:
    Dec 19, 2005
    Posts:
    141
    Referrals:
    4
    Sythe Gold:
    15
    Between Function?

    thanks, just what i needed :)
     
  9. dodge

    dodge Active Member
    Banned

    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5
    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
     
  10. speljohan

    speljohan Guru
    Visual Basic Programmers

    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0
    Between Function?

    o_O very nice function there dodge. I didn't think you could use regexes that way.
     
  11. dodge

    dodge Active Member
    Banned

    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5
    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
     
  12. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Between Function?

    looks at regex, *passes out*
     
  13. dodge

    dodge Active Member
    Banned

    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5
    Between Function?

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

    nvm me i'm just a bit stoned this morning!
     
  14. speljohan

    speljohan Guru
    Visual Basic Programmers

    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0
    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
     
  15. Cheeter

    Cheeter Grand Master
    Cheetah Retired Global Moderator

    Joined:
    Jun 5, 2005
    Posts:
    3,851
    Referrals:
    1
    Sythe Gold:
    31
    Discord Unique ID:
    236215891849641985
    Discord Username:
    Charkel#8050
    Extreme Homosex Homosex
    Between Function?

    *Sigh* Covey's a noob :p
     
  16. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    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 :)
     
  17. dodge

    dodge Active Member
    Banned

    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5
    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++. >


 
 
Adblock breaks this site