Decode

hi,
I want to write a method
Stringdecode(String text,int shift)

when I will pass 'LIPPS' and 4 it should return 'HELLO'

'ZWBGLZ'
25
'AXCHMA'
LVL 8
Johny BravoAsked:
Who is Participating?
 
deadlyDevConnect With a Mentor Commented:
OK... you can follow the following steps... minimal code so I dont get in trouble :P

Step 1.
Create a string array holding all characters you want to be able to process...
char[] myChars = new char[] { 'A', 'B', 'C', ... 'X', 'Y', 'Z'}

Step 2.
Create a method that takes an offset value and startPosition checks the following...

...1: Is startPosition + offSet less than 0... if yes -> return myChars[startPosition + offSet modulos (%) myChars.Length + myChars.Length]

...2 return myChars[(startPosition + offSet) % myChars.Length];

Step 3.
Loop through the characters in your string, call the method and append the result to a return string

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>I want to write a method
so, what is the problem?

I ask, because this looks like homework, so you should try yourself, and post your findings/problems...
0
 
Johny BravoAuthor Commented:
Can't figure it out.Pls help as i am fresher
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
that's exactly the reason why you have to get "your hands dirty".
now, what is the problem. can you describe, in plain english, what the code should do?
0
 
Johny BravoAuthor Commented:
If I pass LIPPS and 4 then it shud print HELLO
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
well, that is only 1 example, which you posted already.
what you should "say" is how this change should be happening, still in plain english.

note: I know exactly what should be done, just trying to get you say it (learning process)
0
 
Johny BravoAuthor Commented:
L - 4
I - 4
P-4
like this...
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
johny_bravo1,

  so, you want to actually say:
  for each character from the input string, take the ascii code, substract 4, and put the character from that value. return the concatenated result.

  given that, try to get that translated into code:
  § looping the characters in a string
  § get the ascii code from a character
  § get the character from a ascii code
  § concatenate the results

0
 
Pratima PharandeCommented:
thats fine  angelIII .
But that code was not complete code
0
 
Pratima PharandeConnect With a Mentor Commented:
actualy that code will work for
when I will pass 'LIPPS' and 4 it should return 'HELLO'


But nit for any other case like
'ZWBGLZ'
25
'AXCHMA'

Thats the only thing not coded there ..........
I thought I will give some code and he will make the changes in that
but anyways fine .sorry for posting that code
and thanks for deleting it
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I agree: the case to "rotate" over the alphabet range :
A-1 = Z , and Z+1 = A for example are indeed not handled.

johny_bravo1,
 in the pseudo-code explanation, you will indeed need to add a conditonal check if the ascii code determined, with the "shift" value applied (+4, -25) is still in the ascii range or not...
0
 
deadlyDevCommented:
Hey johnny...

Is there a fixed subset of characters you want to use, eg.. the alphabet... the alphabet and numbers.... only caps...?
0
 
Johny BravoAuthor Commented:
Only Capital characters.
By the way it is not homework
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.