Ontani Posted March 28, 2008 Posted March 28, 2008 i have a program that contains the current text in its textbox: Blaaaat Blaaat Blaat Now another program accesses this textbox and reads it out, but some problems occur, with hidden characters messing up some things: aSplitted = strTextBuff.Split(Environment.NewLine) For Each aElement As String In aSplitted Debug.WriteLine(aElement.Length & " - " & aElement) Next the output of this debug is: 7 - Blaaaat 7 - Blaaat 7 - Blaat Not exactly what you would expect, this is what i was expecting: 7 - Blaaaat 6 - Blaaat 5 - Blaat How can i prevent this? What is the problem here? I tried replacing all chrs from 0 to 31 without any success. Anyone an idea? This could be very simple Quote www.purevision.be :: www.devpoint.be
Administrators PlausiblyDamp Posted March 28, 2008 Administrators Posted March 28, 2008 How is the text getting into the textbox? Is this being typed in or has it been entered in the designer? If you take the length of the textbox's contents does it reflect the visible text or the mixture of visible and non visible characters? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ontani Posted March 28, 2008 Author Posted March 28, 2008 The text is grabbed from notepad at this point, this will be in a later stadium a game console. The length of the text is 23 while there are only 18 characters. So Non-Visible characters are included. 20 or 21 characters would be normal (2 or 3 linebreaks) but 23 is just strange. Quote www.purevision.be :: www.devpoint.be
Administrators PlausiblyDamp Posted March 28, 2008 Administrators Posted March 28, 2008 Could you attach the .txt file - I can have a look at it on this pc then and be sure I am using the same data. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ontani Posted March 28, 2008 Author Posted March 28, 2008 nothing much to seePD.txt Quote www.purevision.be :: www.devpoint.be
Administrators PlausiblyDamp Posted March 28, 2008 Administrators Posted March 28, 2008 I always get caught out by this one myself - the String.Split only splits on characters not strings and Environent.NewLine is two characters long. Effectively it means you are getting the line feed part of the carriage return+line feed combination left over. One alternative is to use a simple regular expression - the following should work aSplitted() As String = System.Text.RegularExpressions.Regex.Split(strTextBuff, Environment.NewLine) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ontani Posted March 28, 2008 Author Posted March 28, 2008 That seemed to be the problem, Thank you. Now when i don't press an enter after the last line in notepad anything that follows is discarded, maybe its an EOF character or something like that. Quote www.purevision.be :: www.devpoint.be
Mike_R Posted March 29, 2008 Posted March 29, 2008 You could also try the 'Microsoft.VisualBasic.Strings.Split' method, which can also handle a multi-character string splitter. It might handle your "last character" issue better, don't know... I think it's also a little safer to use in general than RegEx.Split(), unless you really do wish to split on a pattern. In your case you are passing in Cr & Lf, so it's fine, but if you passed in "\d", for example, all heck would break loose, splitting on every digit... You know the source in this case, so it's ok, but if you don't know what the spit value will be beforehand (supplied by the user, perhaps?) then you could get really snagged with RegEx.Split, I think. Quote Posting Guidelines Avatar by Lebb
Ontani Posted March 31, 2008 Author Posted March 31, 2008 Thanks for the heads up, but as you said the source of the split char is know and not defined by any user input. Quote www.purevision.be :: www.devpoint.be
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.