473,659 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Increment String chracter

553 Contributor
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 11062
horace1
1,510 Recognized Expert Top Contributor
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.ht ml

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 New Member
if i am pass "ZAL" Output is "[AL"
It is wrong.
May 2 '17 #3
chaarmann
785 Recognized Expert Contributor
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
4043
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 leading whitespace not_white = s.find_first_not_of(ws);
8
1523
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 over to a string. This doesn't work. It misses data and teh result is not the same as when using char buffer, which gives correct download. Could anyone point out why the ostringstream + string way doesn't work, while the char buffer does? tia...
21
3973
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 data that is in this field can vary. It's a list of mechanical equipment, and how it is designated varies based on how the customer has them labeled. For example, a list of their equipment might look like: CH-1 CH-2 CH-3
8
1375
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 = FileVersionInfo.GetVersionInfo(@dir); Thanks
8
1652
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 I'm obviously not looking in the right area. In VB.NET there is a simple function to tell if one string is contained inside another. For example:
5
8587
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 be wasted. I personally consider String Concatenations to be even bigger evil. Here is test study that shows dramatic performance impact of String Concatenations and how to avoid it. ...
8
1513
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
6270
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 of values to them based on data submitted from POST Fields. Code below: $_SESSION = array();
17
2060
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 textarea and I have list of 90 ro 100 words and special chracter that I do not want user to enter. If they enter the item from the list of blocked word or character I want to give them error saying "this character or word in not allowed, please...
0
8332
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7356
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.