473,387 Members | 1,553 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,387 software developers and data experts.

C# .NET normal to verbatim string conversion

rhitam30111985
112 100+
Hi all ... i have a tricky problem.. cant seem to find a solution to it :

Expand|Select|Wrap|Line Numbers
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace ConsoleApplication1
  8.  
  9.  
  10. {
  11.     class myfunc
  12.     {
  13.      public string GetFileName(string szPath)
  14.        {
  15.             Regex r = new Regex(@"\w+[.]\w+$+");
  16.             return r.Match(szPath).Value;
  17.        }
  18.     }
  19.  
  20.     class Program
  21.     {
  22.         static void Main(string[] args)
  23.         {
  24.             myfunc a = new myfunc();
  25.             string path = "c:\tet\tee\tete.txt";
  26.             string final_path = '@' + path;
  27.             Console.WriteLine(final_path);
  28.             Console.WriteLine(a.GetFileName(final_path));
  29.             Console.ReadLine();
  30.         }
  31.     }
  32. }
  33.  
  34.  
the above code gives me folllowing line of output :

@C: et ee ete.txt
ete.txt

what i am trying to do is convert the normal string to verbatim string so that the escape sequences are ignored and the correct file name is outputted ... is this possible ?

ie .. the output shud be :

c:\tet\tee\tete.txt
tete.txt
May 20 '08 #1
4 5691
Plater
7,872 Expert 4TB
use:
Expand|Select|Wrap|Line Numbers
  1. string path = @"c:\tet\tee\tete.txt";
  2. System.IO.FileInfo fi = new System.IO.FileInfo(path);
  3. Console.WriteLine(path );
  4. Console.WriteLine(fi.Name);
  5. Console.ReadLine();
  6.  
May 20 '08 #2
rhitam30111985
112 100+
No i cant do that becoz i i am using this in a form where the user selects a file using the filedialog class ... the string returned is a normal string .. for further processing i need to convert it .. .
May 20 '08 #3
Plater
7,872 Expert 4TB
The string returned from a filedialog will be correctly escaped and can be used as is.

Also note that I edited my above post.


And an edit here for filedialog usage:
Expand|Select|Wrap|Line Numbers
  1. string fullpath = myOpenFileDialog.FileName;
  2. System.IO.FileInfo fi = new System.IO.FileInfo(fullpath);
  3. Console.WriteLine(fullpath);
  4. Console.WriteLine(fi.Name);
  5. Console.ReadLine();
  6.  
May 20 '08 #4
rhitam30111985
112 100+
oh.. ok ... . will try that ... thanks ..
May 20 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Marcin Kalicinski | last post by:
Why string literals are regarded as char * not as const char *? (1) void f(char *); (2) void f(const char *); f("foo") will call version (1) of function f. I understand that the exact type...
4
by: ouch | last post by:
Hi Everyone, Is there any way to remove the "@" from a verbatim string? I've tried the .remove(int, int) method, but it doesn't work. Thanks ouch
4
by: fred | last post by:
Hi, is there a way to put " (double quote) into a verbatin string? thank you
8
by: Fred | last post by:
Hello, Is there a way to read values from the registry as regular instead of verbatim? Regards, Fred
1
by: Mark Rae | last post by:
Hi folks, Apologies - am having a bit of a "senior moment"... Is there a way to convert a string containing escaped characters into a verbatim string literal? I.e. converting something like...
5
by: tilmann | last post by:
Is there a possibility to concert a string, which is in a column defined as 'FOR BIT DATA', in a normal string, so that i can use the normal string functions? I'm using DB2 V7.2 on z/OS. ...
1
by: oza.hardik | last post by:
Hello, Is there a way to do a verbatim string assignment in JavaScript. Like I could create strings with HTML snippets and reuse in my code. Thanks in advance O
4
by: Nagarajan | last post by:
Is there a way by which I could obtain normal string form of a raw string. XML CDATA is returned as raw string. But I need the string to actually escape special chars. Any idea?
0
by: awyeah | last post by:
Hello everyone, I have some very difficult task to accomplish using ADODB, or DAO in visual basic 6 whichever. This is my masters project and I am stuck!! Say I have a recordset with 4 customers...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.