473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

String not removed

hi,
I have a string, I use the Remove method and the string stays the same.

ublic static bool CreatePrepareFile(string path)

{

Console.WriteLine(path);

int ind = path.LastIndexOf('\\');

Console.WriteLine("index is : {0}", ind);

path.Remove(ind);

This code is to take out the path out of a full filename. The index is
correct, I checked, but the string isn't removed as should!

why ?
Thanks.
Aug 30 '06 #1
2 1197
Nadav wrote:
hi,
I have a string, I use the Remove method and the string stays the same.

ublic static bool CreatePrepareFile(string path)

{

Console.WriteLine(path);

int ind = path.LastIndexOf('\\');

Console.WriteLine("index is : {0}", ind);

path.Remove(ind);

This code is to take out the path out of a full filename. The index is
correct, I checked, but the string isn't removed as should!
Because the Remove method does not alter the string. Instead if
returns a new string without the part to be removed. To use the Remove
method properly, you would need code like this:

string s1 = "ABCDEF";
s1 = s1.Remove(....);

If you need to get a filename without the path, then just use the
Path.GetFileName() method from the System.IO namespace.

Chris

Aug 30 '06 #2
Nadav wrote:
hi,
I have a string, I use the Remove method and the string stays the same.

ublic static bool CreatePrepareFile(string path)

{

Console.WriteLine(path);

int ind = path.LastIndexOf('\\');

Console.WriteLine("index is : {0}", ind);

path.Remove(ind);

This code is to take out the path out of a full filename. The index is
correct, I checked, but the string isn't removed as should!

why ?
Thanks.

Strings are immutable, so all methods return a new string with the
desired modification. So if you write:

path = path.Remove(ind);

it should have the desired effect.

HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm
Aug 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Senthoorkumaran Punniamoorthy | last post by:
I am printing these information. print string.lower(info_res) print string.lower(md5sum(f_md5)) print len(string.lower(info_res)) print len(string.lower(md5sum(f_md5))) print...
5
by: Paul | last post by:
Hi, I'm trying to create an array containing the entire contents of a text file and delimit the elements using vbCrLf. The text file is like this.... -text1 -text2 -text3
25
by: electrixnow | last post by:
in MS VC++ Express I need to know how to get from one comma delimited text string to many strings. from this: main_string = "onE,Two,Three , fouR,five, six " to these: string1 =...
8
by: ais523 | last post by:
I use this function that I wrote for inputting strings. It's meant to return a pointer to mallocated memory holding one input string, or 0 on error. (Personally, I prefer to use 0 to NULL when...
5
by: chris_doran | last post by:
/COMMENT has been removed from the linker that comes with VS2005, and use in source code of: #pragma comment(exestr, "this is a string") gives the message: warning LNK4224: /COMMENT is no...
13
by: Jonathan Wood | last post by:
According to the intellisense help, string.Trim() "Removes all occurances or white space characters from the beginning and end of this instance." However, the follow code does not appear to...
8
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource....
2
by: Steve | last post by:
I am working on a program that works like a check in/check out system. There is a folder on a network drive that stores a bunch of vb programs. This program will check in and check out programs...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.