Solved

How to replace a letter with other letter?

Posted on 2004-10-05
4
228 Views
Last Modified: 2010-04-01
Dear all,

I want to replace each letter that user entered as following:

input     output
a            ah
e            eh
i             ee or ih
o            oh
ö            er
u            oo
ch           sh
au          ow
ei           eye
eu, äu     oy
ie           ee
j             y
qu           kv
s             z or ss
ß             ss
sp           shp
st            sht
sch          sh
th            t
v             f
w            v
z             ts


for example, if user enter 'wie heißt du', then the output is 'vee heyesst doo'. so what is the complete code to convert each letter of user input (if the letter matched one of the input list) into its output ?

Thanks for everyone who can provide the solution.

Regards,
ahwind
0
Comment
Question by:ahwind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:a1programmer
ID: 12230312
how do you determine whether i should be ee or ih ?  and if e always follows i, so that you get ie, do you always output ee, and ignore the i ?
0
 

Author Comment

by:ahwind
ID: 12235537
Dear a1programmer,


Yes, u r right! if i found letter e in the input, then i should check whether it is followed by i or u. if it is i, then i should convert the 'ei' in input into 'eye'.else if it is followed by 'u', the output should be 'oy'. otherwise, just convert the 'e' into 'eh'.

well, the new list is defined as follow:
input     output
a            ah
e            eh
i             ee
o            oh
ö            er
u            oo
ch           sh
au          ow
ei           eye
eu, äu     oy
ie           ee
j             y
qu           kv
s             ss
ß             ss
sp           shp
st            sht
sch          sh
th            t
v             f
w            v
z             ts

is that clear? so may you help me to work out the complete source code ? thanks!

Regards,
ahwind
0
 
LVL 7

Expert Comment

by:a1programmer
ID: 12237965
Sure... Is this actually going to be done using jsp?
0
 

Accepted Solution

by:
msasikala earned 125 total points
ID: 12256607
Hi,
  keep the following method in some util file and use it whereever u want to replace the string

public static String replace(String str)
{
String [] input={"a","e","i","o","ö","u","ch","au","ei","eu","äu","ie","j","qu","s","ß","sp","st","sch","th","v","w","z"};
String[] output={"ah","eh","ee","oh","er","oo","sh","ow","eye","oy","oy","ee","y","kv","ss","ss","shp","sht","sh","t","f","v","ts"};

char[] ch;
String temp;
int len=str.length();
StringBuffer strBuf=new StringBuffer();
boolean bool;

for(int i=0;i<len;i++)
{
     ch=new char[1];
     ch[0]=str.charAt(i);
     temp=new String(ch);
     bool=false;
     if( (temp.equals("i") || temp.equals("e") )&&(i<len-1) )
    {
      ch=new char[2];
      ch[0]=str.charAt(i);
      ch[1]=str.charAt(i+1);
      temp=new String(ch);
      if( (temp.equals("ie"))|| (temp.equals("ei")) ||(temp.equals("eu")) )      {
          for(int k=0;k<input.length;k++)
          {
            if(temp.equals(input[k]))
                    strBuf.append(output[k]);
          }
          continue;
      }else{
                for(int k=0;k<input.length;k++)
                {  
                if(temp.equals(input[k]))
                  strBuf.append(output[k]);
                }
            }
      }else{
            for(int k=0;k<input.length;k++)
            {  
                 if(temp.equals(input[k])){
                  strBuf.append(output[k]);
                  bool=true;
                  }
            }
            if(!bool)
                strBuf.append(temp);
               }
            }
      return strBuf.toString();

}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First of all let me say that the only language that I speak is English, but in answering questions here I often come across people whose English skills are not the best and I’d like to be able to communicate better with them, and the following descr…
Choosing a core focus or particular set of features and options can be tough. To help out, we’re going to highlight a handful of things your business needs on one of your social media pages. In other words, if one of these is missing, you should imp…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question