473,405 Members | 2,262 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,405 software developers and data experts.

String variable strange behavior

I have some string in variable str_tmp = "C:\TMP\"
I want to display it in textbox (@-quoted), so I'm using tbx.Text =
@str_tmp; but for some strange reason this does not work. it processes
escape sequence. What is the problem???

--
Tamir Khason
Who am I at
http://www.khason.biz/

Nov 16 '05 #1
9 1697
Hi,

You are using incorrectly the escape char, use it when you declare your
var:
string srt_tmp = @"c:\tmp";
you don't have to use it when you assign it:
tbx.Text = @str_tmp;
you just do
tbx.Text = str_tmp;
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
I have some string in variable str_tmp = "C:\TMP\"
I want to display it in textbox (@-quoted), so I'm using tbx.Text =
@str_tmp; but for some strange reason this does not work. it processes
escape sequence. What is the problem???

--
Tamir Khason
Who am I at
http://www.khason.biz/

Nov 16 '05 #2
Do not helps.
I have a struct like:

public struct SomeStringStruct
{
public string A_String;
public SomeStringStruct(string a_string)
{
A_String = a_string;
}
}
Now where should I add @ in order to be able to recieve @-quoted strings eg.
SomeStringStruct a = new SomeStringStruct ("\n\n\n")
Console.WriteLine(a.A_String); // Should return \n\n\n and not <CR><CR><CR>

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:eu*************@TK2MSFTNGP11.phx.gbl...
Hi,

You are using incorrectly the escape char, use it when you declare your
var:
string srt_tmp = @"c:\tmp";
you don't have to use it when you assign it:
tbx.Text = @str_tmp;
you just do
tbx.Text = str_tmp;
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
I have some string in variable str_tmp = "C:\TMP\"
I want to display it in textbox (@-quoted), so I'm using tbx.Text =
@str_tmp; but for some strange reason this does not work. it processes
escape sequence. What is the problem???

--
Tamir Khason
Who am I at
http://www.khason.biz/


Nov 16 '05 #3
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote:
Now where should I add @ in order to be able to
recieve @-quoted strings eg.
SomeStringStruct a = new SomeStringStruct ("\n\n\n")
Console.WriteLine(a.A_String); // Should return \n\n\n
and not <CR><CR><CR>


@ is only useful for literal hard-coded strings in your source code.

If you want to convert non-printable characters to the text
representation of their escape sequences (e.g. <CR> to '\n'), you will
have to do the replacements yourself, e.g.

string s2 = s1.Replace("\n", @"\n"); // ... and so on

P.
Nov 16 '05 #4
Tamir Khason <ta**********@tcon-NOSPAM.co.il> wrote:
Do not helps.
I have a struct like:

public struct SomeStringStruct
{
public string A_String;
public SomeStringStruct(string a_string)
{
A_String = a_string;
}
}
Now where should I add @ in order to be able to recieve @-quoted strings eg.
SomeStringStruct a = new SomeStringStruct ("\n\n\n")
Console.WriteLine(a.A_String); // Should return \n\n\n and not <CR><CR><CR>


@ is only applicable to string literals in C# code itself. It affects
how the C# compiler "sees" a string literal, not how the string itself
is then processed.

If you want a string containing carriage returns to be displayed using
"\n" itself, you can do something like:

string replaced = original.Replace("\n", "\\n");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
But I want to be able to replace all \{} sequences eg. \q\n\t etc. Is there
smart way to do it?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Tamir Khason <ta**********@tcon-NOSPAM.co.il> wrote:
Do not helps.
I have a struct like:

public struct SomeStringStruct
{
public string A_String;
public SomeStringStruct(string a_string)
{
A_String = a_string;
}
}
Now where should I add @ in order to be able to recieve @-quoted strings eg. SomeStringStruct a = new SomeStringStruct ("\n\n\n")
Console.WriteLine(a.A_String); // Should return \n\n\n and not
<CR><CR><CR>
@ is only applicable to string literals in C# code itself. It affects
how the C# compiler "sees" a string literal, not how the string itself
is then processed.

If you want a string containing carriage returns to be displayed using
"\n" itself, you can do something like:

string replaced = original.Replace("\n", "\\n");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6
Would string.Replace( "\\", "\\\\" ) work?

"Tamir Khason" wrote:
But I want to be able to replace all \{} sequences eg. \q\n\t etc. Is there
smart way to do it?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Tamir Khason <ta**********@tcon-NOSPAM.co.il> wrote:
Do not helps.
I have a struct like:

public struct SomeStringStruct
{
public string A_String;
public SomeStringStruct(string a_string)
{
A_String = a_string;
}
}
Now where should I add @ in order to be able to recieve @-quoted strings eg. SomeStringStruct a = new SomeStringStruct ("\n\n\n")
Console.WriteLine(a.A_String); // Should return \n\n\n and not

<CR><CR><CR>

@ is only applicable to string literals in C# code itself. It affects
how the C# compiler "sees" a string literal, not how the string itself
is then processed.

If you want a string containing carriage returns to be displayed using
"\n" itself, you can do something like:

string replaced = original.Replace("\n", "\\n");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #7
Nothing, even regex can not detect that \t (\n) is just "\t" but not <TAB>
I tried even Replace(((char)92).ToString(),"DUMMY"); and
..Split(new char[]{(char)92}); // This return 1 member (the whole string)

WHAT TO DO???
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Bill O'Neill" <Bi********@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
Oops, I guess I oversimplified your issue...need more coffee, sorry. Try regex to replace specific tokens.
"Tamir Khason" wrote:
But I want to be able to replace all \{} sequences eg. \q\n\t etc. Is there smart way to do it?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Tamir Khason <ta**********@tcon-NOSPAM.co.il> wrote:
> Do not helps.
> I have a struct like:
>
> public struct SomeStringStruct
> {
> public string A_String;
> public SomeStringStruct(string a_string)
> {
> A_String = a_string;
> }
> }
> Now where should I add @ in order to be able to recieve @-quoted
strings eg.
> SomeStringStruct a = new SomeStringStruct ("\n\n\n")
> Console.WriteLine(a.A_String); // Should return \n\n\n and not

<CR><CR><CR>

@ is only applicable to string literals in C# code itself. It affects
how the C# compiler "sees" a string literal, not how the string itself
is then processed.

If you want a string containing carriage returns to be displayed using
"\n" itself, you can do something like:

string replaced = original.Replace("\n", "\\n");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #8
Tamir Khason <ta**********@tcon-NOSPAM.co.il> wrote:
But I want to be able to replace all \{} sequences eg. \q\n\t etc. Is
there smart way to do it?


Well, there are slow ways and fast ways - but I don't know of any
*particularly* great way. As ever with string manipulation, you can
approach it from various angles. Some things you might want to think
about:

o Using a StringBuilder is likely to be a good idea
o Appending whole chunks of text which don't need escaping is likely
to help
o Creating the StringBuilder to be an appropriate size to start with
will help
o Check to see if your string actually contains anything which needs
escaping before you do anything - you might want to count the number
of escapes, which allows you to create a StringBuilder of *exactly*
the right size
o It's probably worth making the routine flexible so you can easily
specify different things to escape

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #9
Hi Tamir,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to pass strings
using @-quoted strings. If there is any misunderstanding, please feel free
to let me know.

Based on my knowledge, when you pass string parameters like the following:

SomeStringStruct a = new SomeStringStruct ("\n\n\n")

The "\n\n\n" are converted to <CR><CR><CR> immediately before assigning to
A_String. @ can only be added before quotes to indicate that all the
characters in the quotes are a part of the string and the string doesn't
contain escape characters. So if you need to display \n\n\n, the only way
is to use the following:

SomeStringStruct a = new SomeStringStruct (@"\n\n\n")

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #10

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

Similar topics

1
by: Dan Stromberg | last post by:
The below small program is giving strange behavior. At the bottom of the code, please find "this works" and "this doesn't work" comments. Why does one work and the other not? TIA. ...
6
by: Anders Eriksson | last post by:
Hello! I'm using ActivePython 2.3.2 build 232 on Windows 2000 and I have noticed a strange behavior in PythonWin IDE (win32all build 163) I'm from Sweden and we have a couple of letters in our...
1
by: Justice Gray | last post by:
I have the following code encapsulated in an ascx page (user control): namespace MyCompany.Web.UserControls { string webform_namespace = this.GetType().Namespace.ToString(); } Now, when I...
1
by: Maileen | last post by:
Hi, I finished my application butonce again i have some strange behavior with XML/text functions... for example, here below is a function which worked perfectly till now and now generate an...
1
by: Alexander Inochkin | last post by:
Hi! I found same strange behavior of ASP.NET. It is possible this is the bug. Follow the steps:
1
by: hansolox1 | last post by:
The following program simply sets the icon of a form called form1. When I get the name of the embedded icon using GetManifestResourceNames(), I store the name in a string variable called s. The...
0
by: ivb | last post by:
Hi all, I am using DB2 8.1.11.1 on NT with ASP.NET 1.1 When application make connection to database (via ADO.NET), it set "Connection timeout" parameter to 30 seconds. After, when my webpage...
2
by: Antonio | last post by:
Good morning, everyone. Here is the strange behavior: I have a datagrid (dgPIs) with paging enabled. When I click to view any page in the grid, it runs the private void lnkIPReg method,...
0
by: shapper | last post by:
Hello, I am using the new ASP.NET 3.5 ListView and DataPager. Everything is working fine but I am getting a strange behavior in the DataPager. When I click a pager button for the first time...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.