Share this page

# lr_save_searched_string

Searches for an occurrence of a string in a buffer and saves a portion of the buffer after that string to a parameter.

    int lr_save_searched_string( char *buffer, long buf_size, unsigned int occurrence, char *search_string, int offset, unsigned int string_len, char *parm_name );

Alphabetical Listing - C Language Utility Functions

## Arguments

Name | Comments
--- | ---
buffer | The STRING or CARRAY buffer, part of whose contents you want to save.
buf_size | The buffer size.
occurrence | The occurrence number of the search_string (0-based count). For example, if the search_string occurs three times, and you want the second occurrence, set occurrence to 1.
search_string | The string to search for in the buffer.
offset | The number of characters to skip after the end of the search string occurrence.
string_len | The number of characters to save.
parm_name | Parameter name to be used in subsequent lr statements to refer to the saved information. Name is enclosed in double-quotes.

The lr_save_searched_string function searches for string search_string inside string or character array buffer, and finds the nth occurrence of search_string, where n is occurrence plus 1. The sub-string to be saved starts at offset after the end of the nth occurrence of search_string, and has length string_len.

For example:

Copy code

            char cBuff[] = "abc Emma Woodhouse abc Elizabeth Bennet abc William Price";
            lr_save_searched_string(<i>cBuff</i>, strlen(cBuff),
            2, "abc",// Search for third occurrence of "abc"
            1,       // Skip the space after "abc"
            4,       // Put the next four characters...
           "Fannys_brother"); // ... in parameter Fannys_brother.

After the call, the content of parameter Fannys_brother is "Will".

The search_string cannot contain null characters, but the buffer can contain null characters.

Use the lr_save_string function to save strings from character arrays. Use lr_save_searched_string only when you need to save a portion of a character array relative to a string occurrence.

## Return Values

This function returns LR_PASS on success, and a negative value on failure.

## Parameterization

You cannot use standard parameterization for any arguments in this function.

## Example

In the following example, a Certificate is saved to a parameter for later use. The lr_save_searched_string function saves 16 bytes from the "olen" buffer returned by lrt_tpcal, to parameter cert1. The saved string location in the buffer is 9 bytes past the first occurrence of the string "SCertRep".

There is usually header information before the "ScertRep" string that can vary in length, depending on the recording environment. The lr_save_searched_string function is useful in this case, because regardless of the header length, the certificate always begins nine bytes past this string.

Copy code

    /* Request CARRAY buffer 1 */
    lrt_memcpy(data_0, sbuf_1, 41);
    lrt_display_buffer("sbuf_1", data_0, 41, 41);
    data_1 = lrt_tpalloc("CARRAY", "", 8192);
    tpresult_int = lrt_tpcall("GetCertificate",
        data_0,
        41,
        &data_1,
        &olen,
        TPSIGRSTRT);
    /* Reply CARRAY buffer 1 */
    lrt_display_buffer("rbuf_1", data_1, olen, 51);
    lrt_abort_on_error();
    lr_save_searched_string(data_1, olen, 0, "SCertRep", 9, 16, "cert1");

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: