473,387 Members | 1,621 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.

Increment String chracter

553 512MB
Hi Experts

how to implement this in Java . example problem:

1) Input string e.g "HAL"
2) Output IBM ( each letter in string replaced with next character whatever comes in ABC...

Thanks
Apr 1 '07 #1
3 11048
horace1
1,510 Expert 1GB
Hi Experts

how to implement this in Java . example problem:

1) Input string e.g "HAL"
2) Output IBM ( each letter in string replaced with next character whatever comes in ABC...

Thanks
you could use a StringBuffer
http://java.sun.com/j2se/1.3/docs/api/java/lang/StringBuffer.html

which is similar to a String but you can change the contents, e.g.
Expand|Select|Wrap|Line Numbers
  1.   StringBuffer s=new StringBuffer("HAL");
  2.   s.setCharAt(0,(char)(s.charAt(0)+1));
  3.  
incremenets the first character of the string H to I so it becomes
IAL
you could use a loop to increment all the characters
Apr 1 '07 #2
azar04
1
if i am pass "ZAL" Output is "[AL"
It is wrong.
May 2 '17 #3
chaarmann
785 Expert 512MB
Please try to understand the example given. It is not wrong, but it shows you how to replace the first character only. Just do the same for the second and third character. He asks you to do it with a loop yourself.

Another problem is: what should come after "Z"? You say "next character" which is "[" and correct. But if you mean "next letter" then you have define what should happen with the last letter:
1.) Should "Z" stay "Z" because here is no next letter?
2.) Should you start from the beginning of the uppercase letters? that means "A"
3.) Should you start from the beginning of the lowercase letters? that means "a"? (second series of letters)
4.) Should you start with language specific letters? In Germany in many sorting application you would start with all the addition letters (German umlauts like "Ä", "Ö", "ß").
5.) Or should the german umlauts follow directly inside the alphabet, like in the telephone book sorting? (like "Ä" follows of "A" or "Ö" follows of "O". Just think of all the collation orders (of letters) where you have to pick one, for example in the mySql database.
6.) If you really mean "character" instead of "letter" as you have written it, then you must define the character set. In other charater sets there are characters follwing "Z" which are different from ASCII character "[". Just think of the EBCDIC character set...
May 2 '17 #4

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

Similar topics

1
by: Derek | last post by:
A common technique for trimming leading and trailing spaces from std::string is the following: string s(" blah blah blah "); const char* ws= " \t\r"; string::size_type not_white; // trim...
8
by: Bob Smith | last post by:
I am downloading over http port 80 some contents froma site, but the contents is not properly stored after using ostringstream for temporary storage, and later ostringstream::str() for passing it...
21
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the...
8
by: Dakkar | last post by:
I have an illegal character error so i used @ escape character but it doesnt work how can i make this work possible String dir = myproc.MainModule.FileName.ToString(); FileVersionInfo info =...
8
by: Fred Nelson | last post by:
Hi: I'm a VB.NET programmer who has made amazing progress in the C# world in about two weeks. I've come accross something that I can't figure out - I've checked MSDN and Google extensively so...
5
by: psimakov | last post by:
I just read a great article by Dave Johnson on comparative performance of XML and JSON parsing. It is a very important for anyone doing AJAX. But the parsing is not the only place where CPU can...
8
by: Mike9900 | last post by:
I need to get 00021 in "00sddsd00021dsd" and then increment it to become "00sddsd00022dsd". Is there a way? -- Mike
26
by: drako | last post by:
Hi, I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set...
17
by: newcoder10 | last post by:
Hi All, I would like to know what's the best way to write function(global) in asp.net c# Framework 2.0 to check for textbox in a form (i have about 80 textbox on one form and I have many forms and...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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,...

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.