Remove(0,1) with tab characters

Discussion in 'C++' started by Kamin of Ressik, Oct 8, 2012.

  1. I am using MS Visual Studio 2008 C++. Hopefully there is help here
    because I cannot find anything useful at MSDN.

    I am reading in a text based file with over 2000 lines. Each line has
    a tab at the start and I need to remove it to then write to a new file.

    I am using

    array<String ^> ^lines =
    System::IO::File::ReadAllLines(SourceSelector->FileName);

    to read the file to an array.

    Then this to strip away the tab:

    lines[j]->Remove(0,1);

    But nothing being removed. The string has been verified to be the same
    after the coded executes with a breakpoint evaluation.

    Is there something about the fact that it is a a tab character that is
    making it fail to remove the character? I have even tried

    lines[j]->Remove(5,3);

    just to see if it works at all. Nothing is being stripped out of the
    strings.
     
    Kamin of Ressik, Oct 8, 2012
    #1
    1. Advertising

  2. Kamin of Ressik

    Kuroneko Guest

    On Monday, 8 October 2012 11:20:21 UTC-4, Kamin of Ressik wrote:
    > I am using MS Visual Studio 2008 C++. Hopefully there is help here
    >
    > because I cannot find anything useful at MSDN.
    >
    >
    >
    > I am reading in a text based file with over 2000 lines. Each line has
    >
    > a tab at the start and I need to remove it to then write to a new file.
    >
    >
    >
    > I am using
    >
    >
    >
    > array<String ^> ^lines =
    >
    > System::IO::File::ReadAllLines(SourceSelector->FileName);
    >
    >
    >
    > to read the file to an array.
    >
    >
    >
    > Then this to strip away the tab:
    >
    >
    >
    > lines[j]->Remove(0,1);
    >
    >
    >
    > But nothing being removed. The string has been verified to be the same
    >
    > after the coded executes with a breakpoint evaluation.
    >
    >
    >
    > Is there something about the fact that it is a a tab character that is
    >
    > making it fail to remove the character? I have even tried
    >
    >
    >
    > lines[j]->Remove(5,3);
    >
    >
    >
    > just to see if it works at all. Nothing is being stripped out of the
    >
    > strings.


    Are you assigning the value to lines[j]? Remove() returns a new string, but does not modify the old one.

    Here: http://msdn.microsoft.com/en-us/library/d8d7z2kk.aspx
     
    Kuroneko, Oct 8, 2012
    #2
    1. Advertising

  3. Kamin of Ressik <> wrote:
    > I am using MS Visual Studio 2008 C++. Hopefully there is help here
    > because I cannot find anything useful at MSDN.


    First, you are not using plain C++, but C++/CLI, which is a Microsoft
    Extension of C++. Many people here in this newsgroup even consider it a
    different programming language.
    C++/CLI is specifically made to run on the .NET platform. This means it's
    very Microsoft specific and MSDN is indeed the right place to get your
    information.
    A quick google search for "string remove" points me directly to the correct
    page.
    Granted, the description is a bit misleading for .NET framework < 4.0, but
    if you read the details page carefully you should nevertheless find the
    solution.

    > I am reading in a text based file with over 2000 lines. Each line has a
    > tab at the start and I need to remove it to then write to a new file.
    >
    > I am using
    >
    > array<String ^> ^lines = System::IO::File::ReadAllLines(SourceSelector->FileName);
    >
    > to read the file to an array.
    >
    > Then this to strip away the tab:
    >
    > lines[j]->Remove(0,1);
    >
    > But nothing being removed. The string has been verified to be the same
    > after the coded executes with a breakpoint evaluation.
    >
    > Is there something about the fact that it is a a tab character that is
    > making it fail to remove the character? I have even tried
    >
    > lines[j]->Remove(5,3);
    >
    > just to see if it works at all. Nothing is being stripped out of the strings.


    For Framework 4.0 the description is: "Returns a new string in which a
    specified number of characters in this instance beginning at a specified
    position have been deleted."

    Additional hint: strings in .NET are generally immutable.

    Just a little warning:
    I wouldn't recommend C++/CLI at all. If you want to do serious .NET
    programming, use C#.

    Tobi
     
    Tobias Müller, Oct 8, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hermit Dave
    Replies:
    0
    Views:
    473
    Hermit Dave
    Jan 22, 2004
  2. News Sympatico
    Replies:
    0
    Views:
    328
    News Sympatico
    May 21, 2005
  3. tab 2 into tab 4 ?

    , Jun 19, 2005, in forum: Python
    Replies:
    2
    Views:
    355
  4. sfp
    Replies:
    1
    Views:
    534
    mrcakey \(The Eclectic Electric\)
    Feb 5, 2007
  5. rvino
    Replies:
    0
    Views:
    4,720
    rvino
    Aug 14, 2007
Loading...

Share This Page