Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to replace a letter with other letter?

Posted on 2004-10-05
4
Medium Priority
?
231 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Files go missing when using DFS (Distributed File System) Replication and how to recover them and fix it.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

670 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