Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to concatenate two strings into a single string.for ex:- a path to a text file like i have a my first string as "~/Upload/" and a filename as "abc.txt".I want to combine them as "~/Upload/abc.txt".How can i do this?Help Me..

Thanks in advance..
Posted

C#
string path = "~/Upload/";
string filename = "abc.txt";
string result = path + filename;
 
Share this answer
 
Comments
Krunal Rohit 8-Mar-14 1:19am    
5.
-KR
Peter Leow 8-Mar-14 1:31am    
Thanks, Krunal.
 
Share this answer
 
Path.Combine[^] is another nice and easy way of doing a concatenation with path.
 
Share this answer
 
Hi,
If you have two strings then you can directly add both the string or else you have to fetch both path and string name from where want to and then you can add these both like
C#
string originalpath="~/Upload/";
string Filename="abc.text";
string finalPath=originalpath+Filename;
 
Share this answer
 
You can use plus (+) sing to concatenate more than one string

for ex.

string a;
string b;
string c;
a = "Hello";
b = "World";
c = a + b;

and if you want to concatenate more string in VB then use (&) sign.

Dim a as string;
Dim b as string;
Dim c as string;

a = "Hello";
b = "World";
c = a & b;

Please mark as a answer if it is helpful to you...

Thanks,
Vipul
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900