473,386 Members | 1,803 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.

C# String Operations - Question

Hello all.
Is there a command that can be used to change the string "New York
Collection Letters.pdf" to "New York Collection Letters_200509.pdf"? (right
or variation of substring)

Basically what I have been tasked to do is copy a file from one place to
another changing the name of the file at the same time which may sound easy,
but I am very new to .net. I have figured out how to copy a file in C#
and how to get the year and the month from the current date. I just can't
figure out how to insert the year and month at the end of the file name.

Any help is greatly appreciated.

Rhonda
Nov 17 '05 #1
2 1466
Hi Rhonda,

Sure is, you can use String.Insert. To find the position to insert at use Path.GetFileNameWithoutExtension or subtract the length of Path.GetExtension.
On Sun, 25 Sep 2005 19:17:26 +0200, Rhonda Tipton <Rt*******@excite.com> wrote:
Hello all.
Is there a command that can be used to change the string "New York
Collection Letters.pdf" to "New York Collection Letters_200509.pdf"? (right
or variation of substring)

Basically what I have been tasked to do is copy a file from one place to
another changing the name of the file at the same time which may sound easy,
but I am very new to .net. I have figured out how to copy a file in C#
and how to get the year and the month from the current date. I just can't
figure out how to insert the year and month at the end of the file name.

Any help is greatly appreciated.

Rhonda


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2
Hi,

You could use code like the following

string filename = "New York Collection Letters.pdf";
string newFilename = string.Format("{0}_{1}{2}",
Path.GetFileNameWithoutExtension(filename),
DateTime.Now.ToString("yyyyMM"),
Path.GetExtension(filename));

I used string.Format, you could also just use straight string concatenation
Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Rhonda Tipton" <Rt*******@excite.com> wrote in message
news:GY*******************@tornado.texas.rr.com...
Hello all.
Is there a command that can be used to change the string "New York
Collection Letters.pdf" to "New York Collection Letters_200509.pdf"?
(right or variation of substring)

Basically what I have been tasked to do is copy a file from one place to
another changing the name of the file at the same time which may sound
easy, but I am very new to .net. I have figured out how to copy a file
in C# and how to get the year and the month from the current date. I just
can't figure out how to insert the year and month at the end of the file
name.

Any help is greatly appreciated.

Rhonda

Nov 17 '05 #3

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

Similar topics

5
by: Dave | last post by:
I'm receiving info from a com port into a string. I gradually process the string which constantly shortens it. The question is how long can a string be before I need to write some info to disk...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
2
by: Dan Schumm | last post by:
I'm relatively new to regular expressions and was looking for some help on a problem that I need to solve. Basically, given an HTML string, I need to highlight certain words within the text of the...
29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
25
by: Bala2508 | last post by:
Hi, I have a C++ application that extensively uses std::string and std::ostringstream in somewhat similar manner as below std::string msgHeader; msgHeader = "<"; msgHeader += a; msgHeader...
9
by: j_depp_99 | last post by:
My program reads in hex values from a file and then performs arithmetic operations on them. All works well except when I use large hex values and my answers are incorrect. For example...
8
by: Keith Thompson | last post by:
Kevin Smith <no@spam.comwrites: You posted this to microsoft.public.dotnet.languages.csharp, where I presume it's topical. Why on Earth did you redirect followups to comp.lang.c? Anyone...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.