http://www.technicalpage.net/search/label/SQL

decodeString

 // given a=1, b=2,....z=26 , now covert/decode the given Word/String with the number

 package abc;

import java.util.Arrays;

public class DecodeString {

 

       public static void main(String[] args) {

             String[] abc = new String[26];

             int[] num = new int[26];

             String word = "abcdefghijklmnopqrstuvwzyz" ;

             int strLength = word.length();

             for(int i=0;i<strLength;i++) {

                    abc[i]=Character.toString(word.charAt(i));

                    num[i]=i+1;              

             }

             System.out.println(Arrays.asList(abc));

             System.out.println(Arrays.toString(num));// it works

             System.out.println(Arrays.toString(abc));// it works

             System.out.println(Arrays.asList(num));// this does not work,do not use.

            

             String givenString = "umbrella";

             int word1Length = givenString.length();

             int indexOfeachChar = 0;

             int[] indexOfchar = new int[word1Length];

             String trimm = " ";

             for(int i=0;i<word1Length;i++) {

                    indexOfchar[i] = Arrays.asList(abc).indexOf(Character.toString(givenString.charAt(i)));

                    System.out.print(indexOfchar[i]); //there is no 'ln'

                    trimm = trimm.concat(Integer.toString(indexOfchar[i]));

             }

             System.out.println();

             System.out.println("Given string = "+givenString);

             System.out.println("The characters in Array : "+Arrays.toString(indexOfchar));

             System.out.println("Data Before Trim, this has one space at the begining : " +trimm);

             System.out.println("Final Data for the given string :"+trimm.trim());

       }

}

 

Output:

[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, z, y, z]

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]

[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, z, y, z]

[[I@4926097b]

2012117411110

Given string = umbrella

The characters in Array : [20, 12, 1, 17, 4, 11, 11, 0]

Data Before Trim, this has one space at the begining :  2012117411110

Final Data for the given string :2012117411110

 

No comments:

Post a Comment