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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

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 PharandeCommented:
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
deadlyDevCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.