text Box & strings

.net , vb6 United States
  • 18 years ago

    I place text from a file in a text box. I get "Hello//"How can I remove the 2 lines that apear at the end of the line. I did it once but can't remember.
    Somthing about seltext and seltext -2 or somthing like that


  • 18 years ago

    Well, just for that string you can do this: (assuming that strFile is the variable that holds the text)


    strFile = Mid$(strFile,1,len(strFile) - 2)


    what it does is that it calls the function Mid$ with the following arguments:


    strFile = the string to be edited
    1 = starting position
    len(strFile) - 2 = where to end...


    len(strFile) gets how long the string is, subtract 2 from it and you'll just get "Hello"




    Hope its not too confusing or elaborate

  • 18 years ago

    i think you mean  left$(mytext, len(mytext)-2)  would return "hello"


    does the same thing ~ its up to you

  • 18 years ago

    I have this little routine that i use to remove specific chars from a string:


    Code:
    Public Sub Purge_string(ac As Integer, text$)
    'this routine purges a specified char from a string
    'ac = ascii code for char to be purged
     Dim p As Integer
     Do
       quo$ = Chr$(ac)
       p = InStr(text$, quo$)
       If p <> 0 Then 'string contains invalid char
         text$ = Left$(text$, p - 1) + Right$(text$, Len(text$) - p)
       End If
     Loop Until p = 0 'string purged!
    End Sub


    It just does that same as what kimmy and tony suggested, but with this code it does not matter where the unwanted chars are (ie they could be in the middle or at the begining of the string).


    Stevesoft

  • 18 years ago

    in .NET I dont think there is a Left$... do you know why MS took it out?  I was going to suggest what Kimmy was going to say, but it doesn't work for .NET so I just thought Mid$ would be best cuz it works with both versions

  • 18 years ago

    Can someone confirm that left$ has been excluded in .net ???


    if so, it may be a good enough reason to start to convert my progs to use mid$ instead of left$ (and maybe right$).


    I understand that .net attempts to convert vb6 programs to run under .net, in this case would the left$ be converted to mid$ ???


    These sort of things are good to know and bear in mind if you are considering upgrading to .net at some point.


    Stevesoft

  • 18 years ago

    I'm actually wrong, sorry about that...


    When you type in Left() it lets u get or set the x-coordinate of the edge of the form in pixels


    Left$ is in... Microsoft.VisualBasic.Left$() ... This is what you get for making something so big! (cough) .NET Framework (cough)


    Sorry about my early assumption

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” - Tom Cargill