Results 1 to 8 of 8

Thread: [RESOLVED] string.remove() help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Resolved [RESOLVED] string.remove() help

    Hey.
    I am building an app that displays a log file from mirc onto my g15 display.
    I want to remove the written timestamp infront the text, in the log file.
    I do it this way:

    vb.net Code:
    1. Private Sub RefreshLCD()
    2.         Dim ts As String() = temp.Split(Chr(10))
    3.         For g As Integer = 1 To ts.Length - 1 Step 1
    4.             If ts(g).Contains("<") Then
    5.                 ts(g) = ts(g).Remove(0, ts(g).IndexOf("<"))
    6.             End If
    7.         Next
    8.     End Sub
    9.     'Yes there's more code, but it's that part i'm talking about.

    The problem is, it DOESN'T remove the timestamp. I've tried breakpointing it and it does find a < sign.

    Here's the text that the array ts holds:

    Code:
    03[00:56] * jayb ([email protected]) has joined #test
    02[00:58] * jayb ([email protected]) Quit (Signed off)
    00[01:12] <Linkyyy> test
    00[01:12] <Linkyyy> test
    00[01:12] <Linkyyy> test
    00[01:12] <Linkyyy> test
    Session Close: Wed Jun 03 01:24:26 2009
    If you need the whole code from RefreshLCD() then say so, and i'll post it.
    Last edited by Link; Jun 4th, 2009 at 10:30 AM.

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: string.remove() help

    The second int in this String.Remove overload is the number (count) of characters that you want to delete.

    Check out this example here. It is exactly what you are trying to do. http://msdn.microsoft.com/en-us/library/d8d7z2kk.aspx

  3. #3
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: string.remove() help

    That should remove the timestamp but only for those lines containing a '<' char. The first two lines don't have that character so those timestamps won't be removed.

    How are you checking to see that the timestamps have not been removed? Are you checking right after that loop?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Re: string.remove() help

    nmadd# Yes, from 0 to <'s position(which also is numbers of chars to delete), shouldn't that be right?

    wy125# I draw the strings(it's in the loop, after that if check, just didn't show it) on a bitmap, and sends it to the lcd screen. (That's how logitech made it... displaying bitmaps..)

    EDIT: So.. yea i actually got this working again by drawing the string onto the bitmap in another for loop...

    Before:
    vb.net Code:
    1. For g As Integer = 1 To ts.Length - 1 Step 1
    2.             If ts(ts.Length - g).Length < 3 Then y += 8
    3.             If ts(g).Contains("<") Then
    4.                 ts(g) = ts(g).Remove(0, ts(g).IndexOf("<"))
    5.             End If
    6.             g1.DrawString(ts(ts.Length - g), myfont, Brushes.Black, xy(0), y)
    7.             y -= xy(1)
    8.         Next
    After:
    vb.net Code:
    1. For g As Integer = 1 To ts.Length - 1 Step 1
    2.             If ts(g).Contains("<") Then
    3.                 ts(g) = ts(g).Remove(0, ts(g).IndexOf("<"))
    4.             End If
    5.         Next
    6. For x As Integer = 1 To ts.Length - 1 Step 1
    7.         If ts(ts.Length - x).Length < 3 Then y += 8
    8.         g1.DrawString(ts(ts.Length - x), myfont, Brushes.Black, xy(0), y)
    9.         y -= xy(1)
    10. Next

    Thanks for answering
    Last edited by Link; Jun 4th, 2009 at 10:36 AM.

  5. #5
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: string.remove() help

    Are you interested in only removing the timestamps from lines only containing "<" characters or all timestamps? If it's all, then you need to do something else. Using the IndexOf() method to remove the time stamp from lines containing the "<" is fine.

    The reason why I ask how you check your results is that it looks like your array after that loop looks good but the results you see are not. There must be a problem between the code where you remove the timestamps and you displaying them. If none of the timestamps are removed (remember your code won't remove the time stamps from the first two lines, so if that's what you mean by the time stamps are still there then you need to change your timestamp-removal method) then it must be that you're not creating the bitmap from the correct source.

    Take a look and make sure you're using the formatted array to generate your output. If you can't find the problem, let's see more of your code where you generate output from the formatted array.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Re: string.remove() help

    Yea i know that it didn't remove the timestamp from join/leave messages. I have coded that now, so it's fine

    I still find it very strange that the first way didn't work, but the second did. But don't waste your time on why, it's fine. I'm greatfull that you tried to help me and answered so fast. Thank you!

  7. #7
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: [RESOLVED] string.remove() help

    well it looks to me that in the first way while you were removing the timestamp from ts(g) you were printing the one from ts(ts.Length - g), which is not the same one you just removed. For instance, on the first iteration, you would have removed the timestamp from index 1 but printed index N-1 which is last one in the array.

    I think if changed ts(g) = ts(g).Remove.... to


    Code:
    if (ts(ts.Length - g).Contains("<")) Then
       ts(ts.Length - g) = ts(ts.Length - g).Remove(0, ts(ts.Length - g).IndexOf("<"))
    then that would have worked. What you were doing was removing the timestamp for a different index than you were printing. This would print everything from the middle index down incorrectly with the timestamp but from the first index to the middle index correctly.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Re: [RESOLVED] string.remove() help

    oh.. Yes you're right. haha, thanks for letting me now. stupid mistake to make

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