Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Exercice Palindrome

Discussion in 'Scripting' started by theofabrin, Nov 29, 2019.

  1. theofabrin

    theofabrin

    Joined:
    Aug 10, 2019
    Posts:
    3
    Hi guys.
    How are you?
    I have this question to solve, but I don't know where to start.
    Could someone help me please?

    Create a function that determines if the input phrase is a palindrome disregarding spaces.

    Thank you very much
     
  2. Neriad

    Neriad

    Joined:
    Feb 12, 2016
    Posts:
    125
    If this is an exercise then I guess I'm not supposed to give you the answer like that but here are a few tips :

    Lets imagine I have the string : string s = "hello world";
    You can easily say when you look at it that its not a palindrome, as s[0] (h) and s[s.Length - 1] (d) are different characters.

    But now if you have the string : string s = "radar";
    s[0] and s[s.Length -1] are both 'r', s[1] and s[s.Length -2] are both 'a'.

    Now you need to translate that to scripting.
     
  3. theofabrin

    theofabrin

    Joined:
    Aug 10, 2019
    Posts:
    3
    Thanks a lot.
    I'll Try to put this to a script.
    anything, i'll try here some ideas.

    Thanks again
     
  4. Thibault-Potier

    Thibault-Potier

    Joined:
    Apr 10, 2015
    Posts:
    206
    Hi,
    just to satisfy my curiosity, what exactly / where are you studying ? (I guess it's a school homework ? )

    godd luck
     
  5. theofabrin

    theofabrin

    Joined:
    Aug 10, 2019
    Posts:
    3
    Yeap, graduate homework.
    Was given 50 exercices, I made almost. But The theacher told me to deliver this, one of that I didn't manage to solve hahahahahahha.
    So If anyone Give some ideias, I'll be thankful