Palindrome of string without using Reverse function?

Hey @BlackCurrant

Yes, we have this. You need to just check the properties panel of for-each.

Thanks
#nK

1 Like

@Nithinkrishna ,

You mean this?

1 Like

Yep right @BlackCurrant

Hello @Yoichi ,

What is b and i here?

yourString.Take(CInt(Math.Ceiling(yourString.Length/2))).Select(Function(c,i)

c=yourString(yourString.Length-1-i)).All(Function(b) b)

@Nithinkrishna ,

But it is throwing error

Compiler error(s) encountered processing expression “strVal(strVal.Length - ForEach(out_intA)+1).Equals(item)”.
No accessible non-generic ‘ForEach’ found.

1 Like

Screenshot of the code please ?

@Nithinkrishna,

Here it is -


1 Like

Hi,

What is b and i here?

In this case, b mean boolean type variable which is output by previous method : Select.
And i means index number of iteration of Select method.
These are anonymous function of LINQ. Please see the following document in details.

Regards,

Hey @BlackCurrant

It’s due to invalid statement, here it is …

str_Var(str_Var.Length-out_intA+1).Equals(item)

Thanks
#nK

Hello @Nithinkrishna ,

This method is not working, it’s comparing all the characters in the loop one by one.

Can you please suggest me where did I made the mistake and how to correct it?

1 Like

Hey @BlackCurrant

Sorry, That’s my mistake actually. Missed the 1/2 logic part !

Now change the for-each source value as below instead of a simple char array conversion

strVal.Take(CInt(Math.Ceiling(strVal.Length/2))).ToArray

Thanks
#nK

1 Like

@Nithinkrishna ,

Still the same

Check the output

strVal=“madam”

but in output it’s taking all the characters.

1 Like

How many logs were printed please ?

@Nithinkrishna,

3 times
image

1 Like

Which looks perfect then :slight_smile:

1/2 of the word is checked & decided !

1 Like

@Nithinkrishna

That’s is good…but the main problem is whole string should give me the output of palindrome.
Not a particular character.
Although due to the For Each loop it’s comparing all the characters in the string.

But the resultant output should be

“madam” —> is palindrome
“geek” —> not a palindrome

just like how we do it in other programming language.

1 Like

Hey @BlackCurrant

Create a new boolean variable as bol_Palindrome with default value as True

Remove the WriteLine activity in the Then block

Then just replace the WriteLine activity with Assign activity in the Else block, with the below statement

bol_Palindrome = False

Add a Break activity below the above Assign

After the For-Each completion, just add a Log message with below statement,

strVal + if(bol_Palindrome, " is a Palindrome", " is not a Palindrome")

Hope this helps

Thanks
#nK

1 Like

@Nithinkrishna

Yes it worked. Thanks a lot :slightly_smiling_face:

1 Like

Hey @BlackCurrant

Cool buddy :slightly_smiling_face::+1:

Thanks
#nK

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.