PC Review


Reply
Thread Tools Rate Thread

C# String Operations - Question

 
 
Rhonda Tipton
Guest
Posts: n/a
 
      25th Sep 2005
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


 
Reply With Quote
 
 
 
 
Morten Wennevik
Guest
Posts: n/a
 
      25th Sep 2005
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 <(E-Mail Removed)> 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]
 
Reply With Quote
 
Chris Taylor
Guest
Posts: n/a
 
      25th Sep 2005
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" <(E-Mail Removed)> wrote in message
news:GYAZe.28018$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fast String operations kelvin.koogan@googlemail.com Microsoft VC .NET 3 3rd Sep 2008 04:52 PM
Slow String operations... Mugunth Microsoft C# .NET 18 21st Feb 2008 04:15 PM
string operations graphicsxp Microsoft VB .NET 3 27th May 2006 06:47 PM
string operations Sam Microsoft VB .NET 4 13th Jun 2005 02:54 PM
Fast string operations Chad Myers Microsoft C# .NET 17 2nd Jun 2005 07:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:31 PM.