Remove(0,1) with tab characters

  • Thread starter Kamin of Ressik
  • Start date
K

Kamin of Ressik

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.
 
K

Kuroneko

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
 
T

Tobias Müller

Kamin of Ressik said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top