Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Remove(0,1) with tab characters (http://www.velocityreviews.com/forums/t953163-remove-0-1-with-tab-characters.html)

Kamin of Ressik 10-08-2012 03:20 PM

Remove(0,1) with tab characters
 
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.



Kuroneko 10-08-2012 03:49 PM

Re: Remove(0,1) with tab characters
 
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

Tobias Müller 10-08-2012 04:22 PM

Re: Remove(0,1) with tab characters
 
Kamin of Ressik <kamin@ressik.com> 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


All times are GMT. The time now is 10:19 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.