Results 1 to 18 of 18

Thread: [RESOLVED] String Manip.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Resolved [RESOLVED] String Manip.

    I'm hopin someone can help me out. I have a string and I want to count back say 16 characters from the end of the string and delete everything after i counted back that 16 characters. For example if i have:
    ABCDEFGHIJKLMNOPQRSTUVWXYZ then I want to make it:

    KLMNOPQRSTUVWXYZ

    Thanks for any help, it's greatly appreciated

  2. #2
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: String Manip.

    Try the left or right.

    Code:
    text1=Right("ABCDEFGHIJKLMNOPQRSTUVWXYZ",16)
    text1=left("ABCDEFGHIJKLMNOPQRSTUVWXYZ",16)

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: String Manip.

    Thank you But i've encountered another problem, it actually seems like that won't work out for what I'm trying to do. But I do have an idea I know will work. Is there anyway to do an instr search starting from the back instead of the front... so with something like
    [CODE=VB]strinfo2 = Mid(strinfo2, InStr(strinfo2, "string2searchfor"))[/CODE]
    Usually that would find the first one from the top, is there anyway to find the first one from the bottom? Thanks

  4. #4
    Addicted Member
    Join Date
    Jun 2006
    Posts
    172

    Re: String Manip.

    The above way works perfect, but let's say the world didn't have Right() and Left() (plus, I'm super bored trying to make time go by)

    vb Code:
    1. Dim cutOff As Integer
    2. Dim s As String
    3. Dim finalStr As String
    4.  
    5. s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    6.  
    7. cutOff = Len(s) - 16 'can replace 16 with a varible
    8.  
    9. finalStr = Mid(s, cutOff + 1)
    • If you found my post to be helpful, please rate me.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: String Manip.

    No, you don't understand that way to did work perfect but not for what I'm trying to do, because I just discovered the data im trying to parse out from the string isn't always the same length, so I can't use that function because It's based on length. I'm pretty sure the easiest way to do this would do to as i said in my above post. Thanks

  6. #6
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: String Manip.

    What exactly are you trying to do? Are you trying to get a certain amount or characters based on a given value?

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: String Manip.

    basically the big string i have is organized in the following way:
    <item#="1234213"><itemname="itemName"><itemplay=0> and a bunch of other tags and theres a bunch of them. I'm trying to parse out one based on the item name and I want to get the item number. I used strinfo2 = Mid(strinfo2, 1, InStr(strinfo2, Text5.text) - 1) where text5.text is the itemname to delete everything following itemname=. But then I still have a bunch of other items and things before the item number So i just want to do something similiar to Mid(strinfo2, 1, InStr(strinfo2, Text5.text) - 1) except go in reverse so i can just search and delete everything before <item#=. Sorry if im not clear enough, thats the best I can explain it. And I can't use the left, right method because the itemnumber isn't always the same amount of characters

  8. #8
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: String Manip.

    This works and prevents an error in the amount being removed (chopped) from the beginning.
    Code:
    Dim MyString As String, ChoppedString As String
    Const Chopped = 16 ' Set this to anything you like.
    
    Private Sub Form_Load()
    MyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*(98"
    If Chopped <= Len(MyString) Then
        ChoppedString = Right$(MyString, Len(MyString) - Chopped)
        MsgBox "Here's my chopped string: " & ChoppedString
    Else: MsgBox "Cannot chop this much off my string."
    End If
    End Sub
    Doctor Ed

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: String Manip.

    But that also still would only work if every number I was trying to parse out was the same length, which they aren't. The beginning with the abcdef... was only an example, that was my fault, it wasn't a very good one. But thanks for trying though.

  10. #10
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: String Manip.

    You can get the item# with

    Code:
    Dim lngStart As Long
    lngStart = InStr(1, Text1, """")
    Text2 = Mid(Text1, lngStart + 1, InStr(lngStart + 1, Text1, """") - lngStart - 1)

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: String Manip.

    That didn't work... here let me paste an actual portion of what I'd be getting.
    Code:
    <song bsid="2537561" title="Wake Me Up When September Ends" songid="0" plays="3410900" comments="" rate="" downloadable="" imagename="http://b7.ac-images.myspacecdn.com/01812/76/42/1812782467_m.jpg" imagedesc="American Idiot<br>2004" filename="Oy9/sI/vlB4ESwRPIqupfKlqv5iSasA7y7OcPch/Adm94zVHPlCZI6+JeaKBNkCiFQqhGWzc5W9WwBnhXzVH5nxtJYUuDezgFTFodZq4/zE=" url="http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAOPoIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECNrDdOo%2fJWSLBBBOuq0gq%2bcRbLaz%2bBxzmEfDBFBnO6q84puQ03uae97mjQfXww0zKibAw5uE4pfq6cRW4DdzIcg9B5x5IDmOQ04VqNdXOUlUdOvj3XP%2bTvPamSShsNr5d%2brSks25P0d0aR24gQ%3d%3d" lyrics="" purl="" durl="http://cache05-music01.myspacecdn.com/36/std_333f735ab3726b2ebfad03afd56b5261.mp3" token="H8Wzb9noj5oedE+8hbb1V77uxPCrj1o5D1xtV8cpkgzrzsqhrnlzfvn9bJQvPmdKUG/6ZcHAJ8qPjN44YrVTocW/wFgvEcWzW5jSiukcShs=" curl="http://content.music.myspace.com/music.ashx?bandid=2457388&songid=2537561&p=ODgvMzcvMjQ1NzM4OC8yNDU3Mzg4X2M0OWU4NWM3"/>
    <song bsid="63590" title="American Idiot" songid="42040" plays="3307648" comments="42040" rate="42040" downloadable="" imagename="http://c.myspace.com/BandSongs/88/37/2457388/bs213541994_m.jpg" imagedesc="American Idiot<br>2004 Warner Bros." filename="/Nlh4NFQwr5HCJAIe98pTF7+ACoGZ8X5nAk818f1VlfyZl7yxqZyiKS1nhBhnCDdxsoZeHqC2y2e87V5qsm7CE4Ks5M4lFv4UjqA6n3L/HI=" url="http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGVBgorBgEEAYI3WAOPoIGGMIGDBgorBgEEAYI3WAMBoHUwcwIDAgABAgJmAwICAMAECFLY%2fNugzCr0BBCRCEolJrd2B3G6afK07vSNBEj%2f1isqobD8A7tycmj9beT8niwD4ns3%2b8XT%2fXMgVmx%2faM7vGQWiixcAqjxLXmm3iFkq6vnnOc6EabaeGyQrlwc6ekp8qebd8nU%3d" lyrics="63590" purl="" durl="http://cache03-music01.myspacecdn.com/17/std_5daddf4970e9d782e8cb8af6cc862262.mp3" token="NnRv/p2iCHg3pI8MLFza+FeWyH5dk3JAVbHWwywbXKpVwOGCx+VuLxg4w2pBGjhvhKsaCXkhAdBobzn69JpszgTW1XML+lgaVb98iJ2pUYw=" curl="http://cache03-music01.myspacecdn.com/17/std_5daddf4970e9d782e8cb8af6cc862262.mp3?bandid=2457388&songid=63590&p=ODgvMzcvMjQ1NzM4OC8yNDU3Mzg4X2ZhYTAyYjY4"/>
    <song bsid="44325977" title="Give Me Novocaine" songid="0" plays="826304" comments="" rate="" downloadable="" imagename="http://b8.ac-images.myspacecdn.com/01812/86/65/1812775668_m.jpg" imagedesc="American Idiot<br>2004 Reprise" filename="NgB7TAUEHuEp7lKr0CbdMTO9nXKmoDnlVNrxpDB/biYlq1zIQeH4BDRAfva1hLnhSmqxG2WVe2oQ4M1TU3B2u/DWNYz9fAdB1+pUy5ViF3w=" url="http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAOPoIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECNvdifLkpba7BBBXFyAu2gwGWqNx%2fq2SRDgTBFBfwHibBZ3BC65SRfiuqprgOd%2f1cx49rlqYt4h44m%2bGeS%2feuabg4bmtrWQIRG0rd4N2%2bHKSjD03XLCi5ZqhkNLFbvPqkgIzhvaMO9aNGIfCKw%3d%3d" lyrics="" purl="" durl="http://cache02-music01.myspacecdn.com/16/std_d044ef339b29952d14e4b3e05f675d66.mp3" token="BuRRowYTGMvta7X4xmSwo+geM/fWlMXgLqdg5Q9O7H1JZasn7hQMrmIVng81beFuBAvq2bIPkRPpeXHhcqYcVWi8V+P220+3TDwfGl7l8nE=" curl="http://content.music.myspace.com/music.ashx?bandid=2457388&songid=44325977&p=ODgvMzcvMjQ1NzM4OC8yNDU3Mzg4XzY2MDcwYjY3"/>
    <song bsid="44454499" title="Letterbomb" songid="0" plays="724676" comments="" rate="" downloadable="" imagename="http://b7.ac-images.myspacecdn.com/01812/75/65/1812765657_m.jpg" imagedesc="American Idiot<br>2004 Reprise" filename="w0HZI5+KrdqI66unPXqfGLMyF0L2bGIFtCFVFBgJUGjeRTwdgIL4fgJ35sTerXQ1FU18l/YwGjVhWfYn978I/n9A6NkO0GtR/xouqugYBig=" url="http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAOPoIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECGsSwqI%2f0ycdBBBi4rQwd4uyV79i5rRo%2bV5YBFCQCVHSQuvHSaSZoS4gD%2fd7kSU9xQdVwKeD1Eb8xxEhnDFoWq1CyF9pV3wJbdiZaozVuxJK5OE50ccAh%2flbR3t6vli5CB8Cp098L3RNe87ISw%3d%3d" lyrics="" purl="" durl="http://cache01-music01.myspacecdn.com/2/std_be921737fc2e68a7d836036b00eb1864.mp3" token="xB06NAwAQmGtP8f8aYHPAFdZc+45ZxCKs2rPdQ/CHg5sauS+pMrG4Uldc4uRYq+rUE0d6u5AoxOFysHBy7NKEZplQ2/dFUHTojCZ+cmsBiE=" curl="http://cache01-music01.myspacecdn.com/2/std_be921737fc2e68a7d836036b00eb1864.mp3?bandid=2457388&songid=44454499&p=ODgvMzcvMjQ1NzM4OC8yNDU3Mzg4Xzg5ODMyMThk"/>

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: String Manip.

    I actually figured out a different way... can anybody just tell me how I can just pull the numeric part out of a string such as if i have
    <song bsid="63590" how would I pull the 63590 based on the fact that it is numeric. Thanks

  13. #13
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: String Manip.

    When I put your text in a multiline text box and use the following code it successfully got all the song ids.

    Code:
    On Error Resume Next
    Dim lngStart As Long
    Dim Lines() As String
    Lines = Split(Text1, vbNewLine)
    For i = 0 To UBound(Lines)
    lngStart = InStr(1, Lines(i), """")
    Text2 = Text2 & Mid(Lines(i), lngStart + 1, InStr(lngStart + 1, Lines(i), """") - lngStart - 1) & vbNewLine
    DoEvents
    Next

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: String Manip.

    I'm just trying to get one song id though, because i need to pull the song ID of a specific song. Unless theres a way to edit that code to pull out the song names and match them to the id?
    Last edited by ricky234; Sep 21st, 2007 at 05:39 PM.

  15. #15
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: String Manip.

    How about this quick little function to let you type the name of the song and it returns the ID. You need 3 text boxes. Text1 (contains string), Text2, Text3 (search the song)

    Code:
    Private Sub Text3_Change()
    On Error Resume Next
    Dim lngStart As Long
    Dim Lines() As String
    Lines = Split(Text1, vbNewLine)
    For i = 0 To UBound(Lines)
        If InStr(1, LCase(Lines(i)), LCase("title=""" & Text3.Text)) <> 0 Then
            lngStart = InStr(1, Lines(i), """")
            Text2 = Mid(Lines(i), lngStart + 1, InStr(lngStart + 1, Lines(i), """") - lngStart - 1) & vbNewLine
            DoEvents
        End If
    Next
    End Sub

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: String Manip.

    Thank you! That is what I was looking for. And it did work when I just put the text in a textbox, but unfortunately when I tried adding it to my app, it stopped working. I think it has something to do with the whole string. The whole string is

    <?xml version="1.0" encoding="iso-8859-1"?>
    <profile>
    <timestamp><![CDATA[1190417746]]></timestamp>
    <name><![CDATA[Green Day]]></name>
    <playstoday><![CDATA[5598]]></playstoday>
    <downloadedtoday><![CDATA[0]]></downloadedtoday>
    <totalplays><![CDATA[9779786]]></totalplays>
    <autoplay><![CDATA[1]]></autoplay>
    <allowadd><![CDATA[1]]></allowadd>
    <playlist><song bsid="2537561" title="Wake Me Up When September Ends" songid="0" plays="3411816" comments="" rate="" downloadable=""
    imagename="http://b7.ac-images.myspacecdn.com/01812/76/42/1812782467_m.jpg" imagedesc="American Idiot&lt;br&gt;2004" filename="d+CE7+/s2tWby5wDs23ABI54IXWyCvw+Ih9otuRLZGPxvJ/Nc51OlHtOzv29plw3jJwUXole8GMr3pHXawuLW9gxdb5KnJjgLCdMmOn+X5c=" url="http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAORoIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECJaJZIoOg jmIBBArnpXVIx%2b6eRn7YSY6Uq%2b5BFB5LjxMIJuc33uyJVJbL7Wd0KspJke0mUAx67XXFCpSUSkgrGcNWf%2f%2blrR%2b4T1 2SHjV%2fIP%2bvRjlDtu5jTtT%2bQP0supMWwzIKSLq5dfo6yOllQ%3d%3d" lyrics="" purl="" durl="http://cache05-music01.myspacecdn.com/36/std_333f735ab3726b2ebfad03afd56b5261.mp3" token="OQ7Hw5BNCPIDNAOPExJKgqqobcG4H3SuHBC0k/VGqLXFQ8kk2L6SxcNixQZYgosymXkBkWx9tqQhY1ZAgbMUxDE1oYxwEOw64Gxe+XngIaE=" curl="http://cache05-music01.myspacecdn.com/36/std_333f735ab3726b2ebfad03afd56b5261.mp3?bandid=2457388&amp;songid=2537561&amp;p=ODgvMzcvMjQ1NzM4OC8 yNDU3Mzg4X2M0OWU4NWM3"/><song bsid="63590" title="American Idiot" songid="42040" plays="3308420" comments="42040" rate="42040" downloadable=""
    imagename="http://c.myspace.com/BandSongs/88/37/2457388/bs213541994_m.jpg" imagedesc="American Idiot&lt;br&gt;2004 Warner Bros." filename="jVENSvCw88ju2Ejq5AzbkYX3siHy4a7hXZwTTRIxwRwcKC+3mZTEhwNVfgDF8/bew/cSJAM/g4AYkCSNC2GeRsq2my7Dszb4x18zsGbO4Hw=" url="http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGVBgorBgEEAYI3WAORoIGGMIGDBgorBgEEAYI3WAMBoHUwcwIDAgABAgJmAwICAMAECCSq%2bBR X%2bHtWBBBEHCO2S006ritsYmKIvjJvBEjUX6al43SxvHd6EV9SHvOnzPEHGbUqBwkwxWAZ7Wzqzy%2b%2fqjBFRrlgtaD4Iz0Ie sDftmT8ktf5cd13RYPdaENJRIUrjhrKcWA%3d" lyrics="63590" purl="" durl="http://cache03-music01.myspacecdn.com/17/std_5daddf4970e9d782e8cb8af6cc862262.mp3" token="UtG3828K53ur4vYg2WqQ6j727UvWAAxkYZu0fVbduxPs1w9dzgPwohsUd1pXvuiHQLNdvaWUSvxDCRzgY5xwXNVPGmhD/2SK5SsMqEzcp90=" curl="http://content.music.myspace.com/music.ashx?bandid=2457388&amp;songid=63590&amp;p=ODgvMzcvMjQ1NzM4OC8yNDU3Mzg4X2ZhYTAyYjY4"/><song bsid="44325977" title="Give Me Novocaine" songid="0" plays="826911" comments="" rate="" downloadable=""
    imagename="http://b8.ac-images.myspacecdn.com/01812/86/65/1812775668_m.jpg" imagedesc="American Idiot&lt;br&gt;2004 Reprise" filename="bR915VcmzlKO4G9p4OxZFwIvSNVovghUPjzE2QiZZdtRC2t2tHyEVY3UG35sLXJqYXaqCI7hPqU5v2eCyWzPLK5JVG mdgFnoq/1jW5Fz0iI=" url="http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAORoIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECNkZ54LYE dbVBBCme7SmFUShgPzIhFwi0kj0BFA3fRuKw7p39n%2fkbKxK2WAA6iaA8eFq0NziiNC1feh6OVdp2V7Ftt5XcIka4PIVfToaZ9R XwLyrJMualDc%2fnE2pZIHpbb4yYs0TYNLf%2bkxh%2bA%3d%3d" lyrics="" purl="" durl="http://cache02-music01.myspacecdn.com/16/std_d044ef339b29952d14e4b3e05f675d66.mp3" token="fWc9qQCVghGCruTueUFlYkVcsf19W4+dHz0ew+mR69DiZKSb9PimzUYPQiQXrriPDGiWdWaiP0fnKiQwy5R/j4ul2RSCF7WudZSmAAvMW48=" curl="http://cache02-music01.myspacecdn.com/16/std_d044ef339b29952d14e4b3e05f675d66.mp3?bandid=2457388&amp;songid=44325977&amp;p=ODgvMzcvMjQ1NzM4OC 8yNDU3Mzg4XzY2MDcwYjY3"/><song bsid="44454499" title="Letterbomb" songid="0" plays="725247" comments="" rate="" downloadable=""
    imagename="http://b7.ac-images.myspacecdn.com/01812/75/65/1812765657_m.jpg" imagedesc="American Idiot&lt;br&gt;2004 Reprise" filename="/LRXy+5n0XZx7p0HejFMoDcl5JDxI8A0Cd2bzAtxc6NJ3HK0Lo3XBHhXxGK+oKEHboAfopKyVlh0wTYxZrjlljtFWefpgEiI9Tb4f OrUyas=" url="http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAORoIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECAYjRgv2C U0oBBD7O9NP2VVPtLmTsDc%2fxl0xBFA7hABCHdGu31moSZvQx5ozfDOkdVt9h2kWJIA8Dq46NS1Umva2MUVuxUMgJ6vTGKD5WXQ jkdNjnzcEOII6XHMdxV8ThVzcjygZP3pk%2b66V7g%3d%3d" lyrics="" purl="" durl="http://cache01-music01.myspacecdn.com/2/std_be921737fc2e68a7d836036b00eb1864.mp3" token="rcVDrCLkaDYSjLPDuYqm9UgmRv+Y7xwx6fi1rVRfIDY3j9Ci+RkMr+VCella19qKqXkUWStjQpzDHx3XhvDfKHeAls4Pg 010jQvIzcaaCkE=" curl="http://content.music.myspace.com/music.ashx?bandid=2457388&amp;songid=44454499&amp;p=ODgvMzcvMjQ1NzM4OC8yNDU3Mzg4Xzg5ODMyMThk"/>
    </playlist>
    </profile>

  17. #17
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: String Manip.

    How about this little function. I modified it so it should work for the most part. If it doesn't work message back.

    Code:
    Private Sub Text3_Change()
    On Error Resume Next
    Dim lngStart As Long
    Dim Lines() As String
    Lines = Split(Text1, "<song")
    For i = 0 To UBound(Lines)
        If InStr(1, LCase(Lines(i)), LCase("title=""" & Text3.Text)) <> 0 Then
            lngStart = InStr(1, Lines(i), """")
            Text2 = Mid(Lines(i), lngStart + 1, InStr(lngStart + 1, Lines(i), """") - lngStart - 1) & vbNewLine
            DoEvents
        End If
    Next
    If IsNumeric(Text2) = False Then Text2 = ""
    End Sub

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: String Manip.

    THANK YOU! You've been so much help, problem solved!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width