Commodore
Commodore
753 views

Find whitespace character in string using "index_of" function

Hi there, I want to construct a custom string to show up in a report. To build up that string I use variables and functions like index_of(), substring() and concat(). One of the steps I have to take is to split up a string that comprises two word separated by a whitespace character. A propper approach would be to use index_of() to locate the whitespace and then use the outcome number together with substring() to split the string. However, a whitspace is accepted as a valid argument in the Variable Editor. But it is removed upon saving the ressource (filter, rule, query ... and so on). I tried some Regex stuff (\w, \ ,) and expressions like " " or ' ' ... but the argument is being interpreted as entered so it's not going to work. Any ideas ? Christian (added some screenshots: I marked the whitespace argument in the editor.jpg, the other picture shows before and after of the variable and that the whitespace argument is deleted upon hitting the apply button)
Labels (1)
0 Likes
10 Replies
Absent Member.
Absent Member.

Hi ! what data source is the report built on?
0 Likes
Commodore
Commodore

Hi Arik, the report source is a trend, yet the base data is being collected by a daily run query. Christian
0 Likes
Absent Member.
Absent Member.

Hi Christian,

did you find a solution to this?

I am struggeling with the same issue, wanting to find the possition of the first BLANK/WHITESPACE in a string.

When creating the variable and test it with a teststring and simply entering a black (hitting space key) as the delimiter, everything seems to work fine.

But on actual data this does not seem to work.

Thanks for your response,

Markus

0 Likes
Absent Member.
Absent Member.

I remember a thread from a couple months ago where the focus was on or turned to finding whitespace characters. I have done a little searching on the forums but can’t seem to find it. Doesn’t help the search engine doesn’t play nice with word stemming (eg., space matches space; it doesn’t match spaces).

0 Likes
Absent Member.
Absent Member.

Hi Christian,

i found a solution which works at least, if there is a character following your whitespace which could be interpreted as part of the seperator as well.

See what i mean:

I want to get the last position of a " " (blank)  in a string with indexOf.

I created a variable, selected a base  string field and typed a blank (just hitting space key once in the  second argument field).

Before saving, i tested it with  the calucate feature which gave me the feeling everything would work  fine.

On acutal data my "indexOf Variable" was empty.

Obviously  the problem is, that the blank in the string field gets stripped when  saving the variable.

I was in the lucky position, that  my seperator is acutally a [BLANK]-[BLANK]

So when using [BLANK]-[BLANK] as delimiter, the second  blank gets stripped either way, but the remaining rest [BLANK]- is  enough to get the function working...

Maybe this helps you also,

Regards

0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

I seem to recall someone suggesting using the ASCII representation of the space character (Ascii 32) entered by holding down the ALT key and entering "0032" on the numeric keyboard. I remember trying it, but don't remember my results. If this works for you, let us know.  I like the trick of using "Blank", "Blank" and expecting one of them to be stripped, just remember that the next time you edit the rule, there will only be once space there and it'll also get stripped, so don't edit the rule too much.

0 Likes
Absent Member.
Absent Member.

I think I was the one that suggested using the ASCII for a space by holding down the Alt key and hitting 255 on the numeric keypad (does not work on laptops unless numlock is turned on).  It worked for me in my tests for the previous issue and may be worth trying for this as well.

Absent Member.
Absent Member.

Very, very nice trick

0 Likes
Absent Member.
Absent Member.

Yes, I agree, nice trick, however, my challenge was allowing the others to decipher my variables.

I found this to work well:

0 Likes

Hello All,

I found this topic today while struggling with the same issue - actually I think I found a decent working solution to the matter.

Suppose I want to split "NAME SURNAME" from Target User Name field (names are split by a blank character) in two different variables - NAME and SURNAME. What I do is the following:

1. Define a new String variable to remember Target User Name:

NAME_SURNAME = concat(Target User Name, )

2. Replace the blank character with some other character using evaluate_velocity_template(), new character that can be subsequently used with string functions. In evaluate_velocity_template() function you can use only one blank space as an argument, and it works!

NAME|SURNAME = evaluate_velocity_template($NAME_SURNAME.replaceAll(' ','|'))

3. Convert your new string into a list using as separator the new replaced character - "|":

NAME_LIST = convert_string_to_list(NAME|SURNAME, |)

And from here it is easy, just retrieve information from the list with the get_list_element() function.

The trick with writing the blank character using ASCII did not work for me - I was able to introduce the blank, but when applying it would still disappear.

Hope this helps,

Stefan

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.