Same data does not match with each other

Hello guys,
I’m trying a simple comparison, but for some reason it fails. Well both data are same, but if statement and also assert statement fails:

image

I’ve checked and both are String types.
class java.lang.String
class java.lang.String

I have no idea why this is happening.

hi,

try to use String trim() method

String newString = oldString.trim();

What does it do ?

When I’m trying to check it manually, it works good

String a = “9 999 905.70”
String b = “9 999 905.70”

assert a == b

why I have such a problem.

EDIT: With trim() method, it does not works too.

def newSelectedSourceAccountAmount = selectedSourceAccountAmount.trim() 
def newMaxAmount = maxAmount.trim()

hello,

google is our friend :slight_smile:
trim() removes leading and trailing spaces from Java String

hello,

no issues
import static org.junit.Assert.*;

String a = “9 999 905.70”
String b = “9 999 905.70”

assertEquals(a, b);

assert a == b

you need to check values which are got from UI
print those out and verify

it only looks like are same.
you can try also an .toString on both variables … even if they are already strings. i won’t tell you why

hello,

convert strings to byteArray and verify

import java.nio.charset.Charset
import java.nio.charset.StandardCharsets

try to verify values with bytes
String a = “9 999 905.70”
String b = “9 999 905.70”

assertEquals(a, b);

assert a == b

Charset charset = StandardCharsets.UTF_8;
byte[] byteArrrayA = a.getBytes(charset);
byte[] byteArrrayB = b.getBytes(charset);
System.out.println("Text [Byte Format] : " + byteArrrayA);
System.out.println("Text [Byte Format] : " + byteArrrayB);
System.out.println(Arrays.equals(byteArrrayA, byteArrrayB));

Text [Byte Format] : [57, 32, 57, 57, 57, 32, 57, 48, 53, 46, 55, 48]
Text [Byte Format] : [57, 32, 57, 57, 57, 32, 57, 48, 53, 46, 55, 48]