Results 1 to 24 of 24

Thread: Cutting off last4 characters

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Cutting off last4 characters

    How can I trim the last 4 characters off of a string? Like:

    strSong= "Superdrag - Baby Goes To Eleven.mp3"

    I want to cut the last 4 characters (.mp3) off of the string and save as a new string.

    strNew= Function I need here(strSong)

    Any help appreciated.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    abc = Left(abc, Len(abc) - 4)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Also, how can I?

    How can I check to see if a character exists in a string? Say if I want to check my string for a comma.

  4. #4
    Red Rush-In
    Guest
    VB Code:
    1. strSong = left(strSong, len(strSong) - 4)

  5. #5
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828

    Re: Also, how can I?

    Originally posted by hipopony66
    How can I check to see if a character exists in a string? Say if I want to check my string for a comma.
    VB Code:
    1. If InStr(str,",") > 0 Then Msgbox "Yup!"
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  6. #6
    Addicted Member mepaco's Avatar
    Join Date
    Mar 2002
    Location
    Jackson, MS
    Posts
    185
    locationInString = InStr(1, yourString, ",")

  7. #7
    Red Rush-In
    Guest

    Re: Also, how can I?

    Originally posted by hipopony66
    How can I check to see if a character exists in a string? Say if I want to check my string for a comma.
    VB Code:
    1. If InStr(1, strSong, ",", vbTextCompare) Then
    2.         'Its in there
    3. End If

    TextCompare is not case sensetive, BinaryCompare is.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Also, how can I?

    Originally posted by hipopony66
    How can I check to see if a character exists in a string? Say if I want to check my string for a comma.
    if instr(string,",") then
    msgbox("comma exists")
    end if

    (btw, instr gives the position of that comma)

    edit: corrected

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    first last. crap.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Still one problem......

    Trim off thing isn't working.

    My code is like:
    VB Code:
    1. artist= temp(0)

    How would I cut the last 4 characters off of temp(0)?

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    This doesn't work either

    VB Code:
    1. tmpartist = temp(0)
    2.     artist = Left(tmpartist, Len(tmpartist) - 4)

  12. #12
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    VB Code:
    1. artist = Left$(temp(0), Len(temp(0)-4))
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Not cutting it off

    It's still not cutting off the ".mp3". It doesn't make any sense to me

  14. #14
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    can you paste your code exactly and a few lines before and after it please?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Ok, here goes...

    VB Code:
    1. Dim genretemp As String
    2.  Dim hastag As Boolean
    3.  Dim Tag As String * 3     ' First 3 Chars of 128 byte Tag Info - 'TAG'
    4.  Dim Songname As String * 30
    5.  Dim artist As String * 30
    6.  Dim album As String * 30
    7.  Dim year As String * 4
    8.  Dim comment As String * 30
    9.  Dim genre As String * 1
    10.  
    11.  Dim temp() As String
    12.  Dim x As Integer
    13.  Dim mp3 As String
    14.  
    15. lbltotal.Caption = File1.ListCount
    16. On Error Resume Next
    17. 'start the loop
    18. For x = 0 To File1.ListCount - 1
    19.     lblcurrent = x + 1
    20.    
    21.     filename = Dir1.Path & "\" & File1.List(x)
    22.     mp3 = File1.List(x)
    23.     temp = Split(mp3, " - ") 'split up the info
    24.  
    25. 'check for other exiting ID3 info
    26. Open filename For Binary As #1
    27.     Get #1, FileLen(filename) - 127, Tag
    28.     If Not Tag = "TAG" Then
    29.     Close #1
    30.     hastag = False
    31.         Exit Sub
    32.         End If
    33.         hastag = True
    34.     filename = filename
    35.     Get #1, , Songname
    36.     Get #1, , artist
    37.     Get #1, , album
    38.     Get #1, , year
    39.     Get #1, , comment
    40.     Get #1, , genre
    41.     Close #1
    42. '''''''''end of reading file''''''''''''''''''
    43. 'remember the other fields
    44.     album = RTrim(album)
    45.     year = RTrim(year)
    46.     comment = RTrim(comment)
    47.     genretemp = RTrim(genre)         'read gengre character to "temp"
    48.     genre = Asc(genretemp)          'convert chr-code to ASCII-number
    49.    
    50.     Tag = "TAG"
    51.     artist = Left$(temp(0), Len(temp(0)) - 4)
    52.     Songname = temp(1)
    53.     'Write the tag
    54.     Open filename For Binary Access Write As #1
    55.     Seek #1, FileLen(filename) - 127
    56.     Put #1, , Tag
    57.     Put #1, , Songname
    58.     Put #1, , artist
    59.     Put #1, , album
    60.     Put #1, , year
    61.     Put #1, , comment
    62.     Put #1, , genre
    63.     Close #1
    64. DoEvents
    65. Next
    66.  
    67.  
    68. End Sub

  16. #16
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    thats coz you done it to the wrong variable ya plonker.

    change
    VB Code:
    1. artist = Left$(temp(0), Len(temp(0)) - 4)
    2.     Songname = temp(1)

    to

    VB Code:
    1. artist = temp(0)
    2. Songname = Left$(temp(1), Len(temp(1)) - 4)

    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  17. #17
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    PS: no offence, only messing
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Son of a!!!!!!!

    I noticed that before I read your post! I was looking at the ID3 info in Explorer (Win XP) and I noticed that all of my artist names were 4 characters short! Thanks for the help.

  19. #19
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Plonker! haa... The brits never cease to amaze and amuse me....

    That's just lovely.

  20. #20
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    No offence, but it's true!!!

  21. #21
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828

    Re: Son of a!!!!!!!

    Originally posted by hipopony66
    I noticed that before I read your post! I was looking at the ID3 info in Explorer (Win XP) and I noticed that all of my artist names were 4 characters short! Thanks for the help.
    you're welcome
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  22. #22
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    Originally posted by mendhak
    Plonker! haa... The brits never cease to amaze and amuse me....

    That's just lovely.
    tee-hee

    you should watch "only fools and horses", brialliant british sit-com
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  23. #23
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I've only seen Mr.Bean on the world's most ****ED UP channel, PBS. Other than that, I have no source to watch any british sitcom.... Unless it's on BBC, but it's reception is pretty poor, here in Mongolia.

  24. #24
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    well, for what its worth i havent seen any mongolian sit-coms either
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

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