|
-
Jun 4th, 2009, 09:21 AM
#1
Thread Starter
Addicted Member
[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:
Private Sub RefreshLCD() Dim ts As String() = temp.Split(Chr(10)) For g As Integer = 1 To ts.Length - 1 Step 1 If ts(g).Contains("<") Then ts(g) = ts(g).Remove(0, ts(g).IndexOf("<")) End If Next End Sub '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.
-
Jun 4th, 2009, 09:36 AM
#2
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
-
Jun 4th, 2009, 09:59 AM
#3
Hyperactive Member
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?
-
Jun 4th, 2009, 10:22 AM
#4
Thread Starter
Addicted Member
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:
For g As Integer = 1 To ts.Length - 1 Step 1 If ts(ts.Length - g).Length < 3 Then y += 8 If ts(g).Contains("<") Then ts(g) = ts(g).Remove(0, ts(g).IndexOf("<")) End If g1.DrawString(ts(ts.Length - g), myfont, Brushes.Black, xy(0), y) y -= xy(1) Next
After:
vb.net Code:
For g As Integer = 1 To ts.Length - 1 Step 1 If ts(g).Contains("<") Then ts(g) = ts(g).Remove(0, ts(g).IndexOf("<")) End If Next For x As Integer = 1 To ts.Length - 1 Step 1 If ts(ts.Length - x).Length < 3 Then y += 8 g1.DrawString(ts(ts.Length - x), myfont, Brushes.Black, xy(0), y) y -= xy(1) Next
Thanks for answering
Last edited by Link; Jun 4th, 2009 at 10:36 AM.
-
Jun 4th, 2009, 10:32 AM
#5
Hyperactive Member
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.
-
Jun 4th, 2009, 11:25 AM
#6
Thread Starter
Addicted Member
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!
-
Jun 4th, 2009, 11:39 AM
#7
Hyperactive Member
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.
-
Jun 4th, 2009, 11:58 AM
#8
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|