Page 1 of 1

Cut off Characters

Posted: Mon Nov 18, 2024 1:43 pm
by Steff23
Hello, how can I hide or cut off characters in Stimulsoft starting from a “ “ (space)? The length of the text varies, so Stimulsoft needs to search for the space and then remove the characters after it.

For example: “Hallo Welt” — “Welt” should no longer be displayed.

I already tried that.

Code: Select all


IIF(
    Substring(EMPLOYEES.LASTNAME, 0, 1) == " ",
    Left(EMPLOYEES.LASTNAME, 0),
    IIF(
        Substring(EMPLOYEES.LASTNAME, 1, 1) == " ",
        Left(EMPLOYEES.LASTNAME, 1),
        IIF(
            Substring(EMPLOYEES.LASTNAME, 2, 1) == " ",
            Left(EMPLOYEES.LASTNAME, 2),
            IIF(
                Substring(EMPLOYEES.LASTNAME, 3, 1) == " ",
                Left(EMPLOYEES.LASTNAME, 3),
                IIF(
                    Substring(EMPLOYEES.LASTNAME, 4, 1) == " ",
                    Left(EMPLOYEES.LASTNAME, 4),
                    EMPLOYEES.LASTNAME
                )
            )
        )
    )
)

Re: Cut off Characters

Posted: Mon Nov 18, 2024 2:01 pm
by Lech Kulikowski
Hello,

Try to use the following expression:
{Substring(EMPLOYEES.LASTNAME, 0, EMPLOYEES.LASTNAME.IndexOf(" "))}

Thank you.

Re: Cut off Characters

Posted: Tue Nov 19, 2024 9:44 am
by Steff23
Thank you for the quick response; your approach works very well. However, I now have the following problem: If the character “ “ is not found because it is not present in the string, the entire string gets truncated/hidden.

Re: Cut off Characters

Posted: Tue Nov 19, 2024 11:33 am
by Lech Kulikowski
Hello,

Try to use the following expression:
{(EMPLOYEES.LASTNAME.IndexOf(" ") != - 1 ? Substring(EMPLOYEES.LASTNAME, 0, EMPLOYEES.LASTNAME.IndexOf(" ")) : EMPLOYEES.LASTNAME)}

Thank you.