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

String manipulation


I'm writing a program that requires some string manipulations. Let's say
I have a string

s='x'

Now, the ascii code for 'x' is 0x78. I want to be able to perform
operations on this number, and print the character corresponding to the
results of the operation. For example, the pseudo-code looks like:

-read in string s from external file (for simplicity, we'll keep s='x')

-determine the code for s (should be 0x78 or 120 in base 10), store it in
variable c

-add a literal to c (let's say c=c+1)

-find out which character corresponds to the new code c=0x79

-store the character in a new string s2

At the end of this, I want s2='y'

Any suggestions?

NG

Jul 18 '05 #1
2 1649
"Nicholas Graham" <ns******@ece.ualberta.ca> schrieb im Newsbeitrag
news:Pi**************************************@feyn man.ece.ualberta.ca...
|
| I'm writing a program that requires some string manipulations. Let's say
| I have a string
|
| s='x'
|
| Now, the ascii code for 'x' is 0x78. I want to be able to perform
| operations on this number, and print the character corresponding to the
| results of the operation. For example, the pseudo-code looks like:
|
| -read in string s from external file (for simplicity, we'll keep s='x')
|
| -determine the code for s (should be 0x78 or 120 in base 10), store it in
| variable c
|
| -add a literal to c (let's say c=c+1)
|
| -find out which character corresponds to the new code c=0x79
|
| -store the character in a new string s2
|
| At the end of this, I want s2='y'
|
| Any suggestions?

Take a look at the built-in functions ord() and chr() -- Chapter 2.1 of the
manual.
s = 'x'
c = ord(s)
c 120 c+=1
s2 = chr(c)
s2

'y'

--

Vincent Wehren

|
| NG
|
Jul 18 '05 #2

"vincent wehren" <vi*****@visualtrans.de> wrote in message
news:d3**********@news2.zwoll1.ov.home.nl...
"Nicholas Graham"
| Any suggestions? Take a look at the built-in functions ord() and chr()
-- Chapter 2.1 of the manual.


And more generally, read all of Chap.2 of the Library Reference on builtin
functions and types. Later chapters, most of them, are 'look up when you
need to' type stuff, but C.2 is core material that everyone should read
after the tutorial.

Terry J. Reedy

Jul 19 '05 #3

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

Similar topics

3
by: siddhartha mulpuru | last post by:
We have some rows that we need to do some tricky string manipulation on. We have a UserID column which has userid entries in the format firstname.lastname and i need to change each entry to...
9
by: mjakowlew | last post by:
Hi, I'm trying to use some string manipulation from a file's path. filepath='c:\documents\web\zope\file.ext' I need to extract everthing after the last '\' and save it. I've looked around...
4
by: Jim McGivney | last post by:
Does anyone know of a concise article that covers string manipulation, such as insert, join, pad, etc. Thanks, Jim
7
by: John A Grandy | last post by:
what are the preferred VB.NET analogues for IsNumeric() and Len() and CInt() & similar string-manipulation functions in VB6
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
5
by: Cleverbum | last post by:
I'm not really accustomed to string manipulation and so I was wondering if any of you could be any help i speeding up this script intended to change the format of some saved log information into a...
5
by: Niyazi | last post by:
Hi, Does anyone knows any good code for string manipulation similar to RegularExpresion? I might get a value as string in a different format. Example: 20/02/2006 or 20,02,2006 or ...
3
by: crprajan | last post by:
String Manipulation: Given a string like “This is a string”, I want to remove all single characters( alphabets and numerals) like (a, b, 1, 2, .. ) . So the output of the string will be “This is...
3
by: frankeljw | last post by:
I have 2 Java strings 1st String is a series of names, colons, and numbers ie) Name1:13:Name2:4526:Name3:789:Name4:3729:Name5:6:Name6:44 2nd String is a name ie) Name2 I need to get the...
1
by: adam bob | last post by:
Hello, I'm struggling with an image mechanism I'm trying to build which basically manipulates a URL string. This is the sort URL that is gained from an InfoPath form ...
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:
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
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
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,...

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.