How to compare strings

How to compare strings

  

Hi,

I would like to check how can i compare the two strings? I want to compare the text in column 1 and column 2. If the text in column 1 and column 2 is the same, then i just display the text in column 1 else i will display the text in column1 and column 2.

Hi Jace,

Without more context, it's hard to guess exactly what you are trying to achieve.

Nevertheless, there's the If built-in function that allows you to return a value depending on some condition. You could leave the expression for column1 always equal to column1. And in column2 you could use:

If (column1 = column2, "", column2)

which will only display column2 if the columns are different.

Is that what you want?

If not, can you provide more context or a sample oml?

Cheers,

José


Hi Jace,

Are you able to fix the problem with the solution provided by Jose?

I assume that you are comparing the data by fetching from a table, if so, here is a sample.

If(ListRecords1.List.Current.DataDisplay.Column1=ListRecords1.List.Current.DataDisplay.Column2,
ListRecords1.List.Current.DataDisplay.Column1,
ListRecords1.List.Current.DataDisplay.Column1 +"-"+ListRecords1.List.Current.DataDisplay.Column2)

In this example i am comparing the data in 2 columns and showing the result based on your condition. Assuming that in the ELSE condition you want to show text from both columns by concatenating them. 


Let us know more details if you still didn't get the answers.


Shashank...

Hi,

Sorry for not providing a clearer view of my questions.

So basically my question is what Shashank have mentioned, i want to compare the data fetch from a table. 

For instance, the value is Yellow, Blue in column 1 and the value is Yellow in column 2, i want to display it as Yellow, Blue instead of Yellow,Blue, Yellow.

then i do not want to show two "Yellow" in the screen. that wise i want to compare the value in column 1 and column 2 to avoid duplicate value.


I will give it a try on both the solution provide. thanks

Hi Jace,

As I understand you need output like second table in following image

First table contain original data,

In first column of second table I just add expression

If(
Index(TableColor.List.Current.Color1,TableColor.List.Current.Color2) =-1,
TableColor.List.Current.Color1,
Replace(TableColor.List.Current.Color1,TableColor.List.Current.Color2,"")
)

It first check column2 value present in column1 or not, If not present show data as it is, if same contain found replace that content with empty string.

 


Let me know :)



Hi,

Please accept my apologies for not providing clear question.. Here exactly what i want to do.

Column 1
Column 2
Yellow, Blue
Yellow
Blue,Green
Pink


From the table above, i need to concatenate values of column 1 and column 2. Currently it display in my screen as

Column 1 + Column 2
Yellow, Blue, Yellow
Blue,Green, Pink


I do not want to see duplicate value. It should display as Yellow, Blue instead Yellow,Blue,Yellow.


Thanks,


No problem jace ;)

To achieve this we just need to change on expression.

Delete second column of the second table

Add given expression in column1

If(
Index(TableColor.List.Current.Color1,TableColor.List.Current.Color2) =-1,
TableColor.List.Current.Color1+" "+ColorList.Current.Color2,
Replace(TableColor.List.Current.Color1,TableColor.List.Current.Color2,"")+" "+ColorList.Current.Color2
)


This is output

Please let me know, It solve your problem or not

Just to add to that, in case you have values like "yellow, blue" and "yellow, red" and you want to output "yellow, blue, red" you'll need a different, more complex approach. However, I'd probably take a step back and look at the reason for having comma seperated text in your tables at all. Sounds to me like you're having a data/database problem that you're trying to fix at display time.

Gopal Jite wrote:

No problem jace ;)

To achieve this we just need to change on expression.

Delete second column of the second table

Add given expression in column1

If(
Index(TableColor.List.Current.Color1,TableColor.List.Current.Color2) =-1,
TableColor.List.Current.Color1+" "+ColorList.Current.Color2,
Replace(TableColor.List.Current.Color1,TableColor.List.Current.Color2,"")+" "+ColorList.Current.Color2
)


This is output

Hi,

I have tried on this but my values are empty. I do not know where got wrong


Hi Jace,

Is it possible to have multiple color in column 2?

As Kilian said, my previous solution will not work if there is more than one colour in column 2.


Now,

You have Color1 & Color2 column and both column may have multiple colors, like

column1: Yellow, blue, Red

column2: Yellow, Pink, Blue


And you want All colour in single column like

Column1+Column2: Yellow, Blue, Red, Pink

 

I'm I right?

Jace Jace wrote:

Gopal Jite wrote:

No problem jace ;)

To achieve this we just need to change on expression.

Delete second column of the second table

Add given expression in column1

If(
Index(TableColor.List.Current.Color1,TableColor.List.Current.Color2) =-1,
TableColor.List.Current.Color1+" "+ColorList.Current.Color2,
Replace(TableColor.List.Current.Color1,TableColor.List.Current.Color2,"")+" "+ColorList.Current.Color2
)


This is output

Hi,

I have tried on this but my values are empty. I do not know where got wrong



time to debug... set a breakpoint and see the value in the debug window. If empty, it could be the values of color1 and color2 are empty.

Hi,

Imho you should work on the problem. What I see is that your solution is a bandaid on the actual problem.

As I see it you can fix it much better inside the preparation and/or screen-action where you loop through the records and fix the columns

If you really think about it you could also possible fix it in the aggregate itself  (or use an advanced query)

J. wrote:

Hi,

Imho you should work on the problem. What I see is that your solution is a bandaid on the actual problem.

As I see it you can fix it much better inside the preparation and/or screen-action where you loop through the records and fix the columns

If you really think about it you could also possible fix it in the aggregate itself  (or use an advanced query)

Hello J,

Yes,  Its look like bandaid on the actual problem :)

I also have another option to do this, like

1)Take local variable as list of colors in preparation.

2)Separate color from column1 & column2 based on comma(,) and store into list, but while storing make sure we are not adding color which is already added.

3)Add all list variable into current item of column1 with space and comma

4)loop same for all rows

5)display column1


Please suggest if there is another simple option.


Thanks

Depends how the datamodel.

But the issue smells like you want to pivot data

Gopal Jite wrote:

Hi Jace,

Is it possible to have multiple color in column 2?

As Kilian said, my previous solution will not work if there is more than one colour in column 2.


Now,

You have Color1 & Color2 column and both column may have multiple colors, like

column1: Yellow, blue, Red

column2: Yellow, Pink, Blue


And you want All colour in single column like

Column1+Column2: Yellow, Blue, Red, Pink

 

I'm I right?

Hi Gopal,

Yes. 

Hi J,

Yes, I did think of doing in aggregate or screen action. Still working on it.  As the data is separated by comma (like what gopal have shown), i was thinking to substring it to compare the value.


Hello Jace,

Check attached oml file, that will solve your problem.

You can check output Here.

Let me know it work or not

Solution

Gopal Jite wrote:

Hello Jace,

Check attached oml file, that will solve your problem.

You can check output Here.

Let me know it work or not

Hi Gopal,

Thanks for your help. I manage to work out a solution.

Hi,

Imho you should work on the problem. What I see is that your solution is a bandaid on the actual problem.

As I see it you can fix it much better inside the preparation and/or screen-action where you loop through the records and fix the columns

If you really think about it you could also possible fix it in the aggregate itself  (or use an advanced query)

Like what J. have mentioned, i using aggregate to solve the problem.

First, i add in a new attribute to the aggregate. Then in the value i include a if statement condition to check,

if(Colors.FirstColor like "%" + Colors.SecondColor + "%", Colors.FirstColor, Colors.FirstColor + " " + Colors.SecondColor)

Gopal you could try this method to see it work for you. Because i got what i expected from this solution. :)




Solution

Hi jace,

great solution   

But, in case you have values like 

"yellow, blue" and "yellow, red" 

and you want to output "yellow, blue, red"

will it work?

Gopal Jite wrote:

Hi jace,

great solution   

But, in case you have values like 

"yellow, blue" and "yellow, red" 

and you want to output "yellow, blue, red"

will it work?

I have not try but i guess it should work because i use a like statement. 


Jace Jace wrote:

I have not try but i guess it should work because i use a like statement. 

I guess, it will not work, see the image.

Your code works for first row but for second row it's not