473,549 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert string to the "escaped string"

Hi,
I am trying to convert string to the "escaped string".
example: from "0xf" I need "\0xf"
I am able to do it like:

a="0xf"
escaped_a=("\%s " % a ).decode("strin g_escape")

But it looks a little bit complicated in this beautiful language to me
.....

Regards

Petr Jakes

Nov 22 '05 #1
3 3435
small mistake in my previous posting, sorry!!!!
from "0xf" I need "\xf" of course
and mentioned code gives me "\0xf" of course.

Thanks for your postings

Petr Jakes

Nov 22 '05 #2
Petr Jakes wrote:
I am trying to convert string to the "escaped string".
example: from "0xf" I need "\0xf" I am able to do it like:

a="0xf"
escaped_a=("\%s " % a ).decode("strin g_escape")

But it looks a little bit complicated in this beautiful language to me


I suspect that optimizing for people who want to turn "0xf" into
chr(0) + "xf" isn't exactly a priority...

if that's really what you want, of course. are you sure you didn't
mean to write, say

chr(int("0xf", 0))

(that is, convert 0xf to a character) or

repr(chr(int("0 xf", 0)))

(that is, convert 0xf to a character, and convert that character to a
string literal)

?

</F>

Nov 22 '05 #3
Fredrik, thanks for your posting. I really appretiate your reply and
your way how you kindly answer even stupid newbie's questions on this
mailing list.
I was trying: int("0xf") but I did not have idea about the optional
"base" parameter for the int function.
Thanks a lot.
Petr

Nov 22 '05 #4

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

Similar topics

4
17859
by: Ed Sutton | last post by:
Is there an easy conversion from a hex string, for example "0x1234" to an int? I have written my own many times in other languages, I was just wondering if there might be something already available for doing this. -Ed
4
4697
by: Ping | last post by:
Hi, All, We can use BitConverter.ToString(byte) to a string, but how to get the byte from a string like "AD-A6-0D-1F"?
2
1561
by: privetv7 | last post by:
ppl... HELP!!!!! i don't know how to convert String into char..... for example i can do String input; int number; input = JOptionPane.showInputDialog( "Enter what ever" ); number = Integer.parseInt(input)
2
2348
by: chongo | last post by:
Hi, i'm reading in a bigint value from SQL Server. string s = myReader.ToString()); int intBackColour = System.Convert.ToInt32(s); I'm also reading in other values the same way and it works great except this one value, i'm getting
2
2245
by: Joebloggs | last post by:
Hi I am trying to do an ldap lookup. I can pick up the domain name in the standard format DOMAIN\USERNAME. The problem is the company I work for expects the query in the format DOMAIN:USERNAME. I tried to do a simple string replace to replace \ to : but it turns out the only string you can't replace in c# is \ as it gives the error...
16
3742
by: ondekoza | last post by:
Hello, I need to convert the string "FFFFFFFF" to a long. To convert this string I tried the following: >>> 0xffffffff -1 >>> 0xffffffffL 4294967295L OK, this is what I want, so I tried
10
13617
by: =?Utf-8?B?RWxlbmE=?= | last post by:
I am surprised to discover that c# automatically converts an integer to a string when concatenating with the "+" operator. I thought c# was supposed to be very strict about types. Doesn't it seem like c# is breaking its own rules? This works: int b = 32; string a = "ABC " + b; Result: a = "ABC 32"
6
39250
yabansu
by: yabansu | last post by:
Hi all, I think most of you probably know the two .NET framework functions, namely Encoding.GetBytes(string) and Encoding.GetString(byte), to convert string into byte array and vice versa. Now, I want to do the same thing in pure(unmanaged) C++. I searched the Internet but could not find any satisfactory solutions. I am really in need of...
5
3634
by: Just Another Victim of the Ambient Morality | last post by:
I've done a google search on this but, amazingly, I'm the first guy to ever need this! Everyone else seems to need the reverse of this. Actually, I did find some people who complained about this and rolled their own solution but I refuse to believe that Python doesn't have a built-in solution to what must be a very common problem. So, how...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7473
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5369
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
764
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.