the Internet Windows Android

1C Find the second entry into the string. New working functions with rows

The "string" type is found in all programming languages. It is primitive, and in 1C there are many functions to work with it. In this article we will consider in detail various methods Work with string types in 1C 8.3 and 8.2 on the examples.

Line

In order to convert a variable of any type to a string, there is the "Row ()" function of the same name. The input parameter will be the variable itself, the string representation of which must be obtained.

Row (false) // Returns "No"
Row (12345) // Returns "12 345"
Row (currentData ()) // 2.5.07.2017 11:55:36 "

Convert to the line is possible not only primitive types, but the rest, such as the elements of reference books, documents.

Sokrlp, Sokrel, Cropp

As input parameters of these functions, a string type variable is a variable. Functions remove insignificant characters (spaces, carriages and other spaces): on the left and right side, only on the left side, and only with the right, respectively.

Sokrlp ("Spaces will be removed on both sides") // "Spaces on both sides will be removed"
Sokrel ("spaces will be removed on both sides") // "Spaces left" will be removed "
Socrp ("Spaces on both sides") // "Spaces on the right will be removed"

Lion, rights, media

These functions allow you to cut part of the line. The "Lion ()" function will return part of the line from its left side of the specified length. The function "Right ()" is similar, but the trimming is performed on the right. The "media ()" function allows you to specify the character number from which the string and its length will be highlighted.

Lion ("string variable", 4) // Returns "Straw"
Rights ("Railing variable", 7) // Returns "Eramet"
Media ("string variable", 2, 5) // Returns "Troko"

Strotina

The function determines the number of characters that are contained in the string variable.

Streglin ("The word") // The result will be the number 5

To find

The function allows you to search in any string variable part of the line. As a returned value, the number will be the position that shows the position of the start of the found line. If no coincidences are detected, zero is returned.

Please note that the search is made with regard to the register. If in the initial line there will be more than one entry of the search substring, the function will return the beginning of the first entry.

Find ("Once, two times, two, three", "two") // Function will return the number 6

Empty line

Using this feature allows you to determine whether the string is empty. Ensucted characters, such as space, carriage transfer and others are not taken into account.

"Pupkin Vasily Ivanovich") // Function will return the value of false
Pastastroca ("") // Function will return the value of the truth

Light, Nreg, Treg

These functions are very useful when comparing and converting string variables. "Laugh ()" will return the original line in the upper case, "Nreg ()" in Lower, and "Treg ()" formats it so that the first character of each individual word will be with a capital letter, and all subsequent with small.

Vrega ("General Director") // Returning importance - "General Director"
Nrega ("General Director") // Return importance - "CEO"
Trega ("General Director") // Return Value - "General Director"

Strust

This feature is an analogue of replacement in text editors. It allows you to replace one character or set of characters to other in string variables.

Strust ("Red, White, Yellow", "," ";") // Return "Red; white; yellow"

Strostroke

The function allows you to determine the number of rows separated by the carriage transfer in the text variable.

The cycle, in the example below, three circles will take place, since the Stringslock function will return to 3:

For Ind \u003d 1 via Strokelock ("String1" + characters. PC + "String2" + characters. PC + "String3") cycle
<тело цикла>
EndCycle;

Plugulastrik

This feature works with multi-line text as well as the previous one. It allows you to get a specific string from the text variable.

Plug throughst ("String1" + characters. PC + "String2" + characters. PS + "String3", 2) // Return "String2"

Strirling

The function counts the amount of symbol entry or substring in the desired string.

Stationforms ("A; b; in; g;", ";") // Function will return the number 4

Symbol and codeimvol

These functions allow you to receive a symbol in its code in Unicode encoding, as well as define this code on the symbol itself.

Knifeimvol ("A") // Function will return the number 1 040
Kodsimvol (1040) // Function will return "A"

Frequent tasks when working with rows

Combining string

To combine several lines (concatenate) it is enough to use the addition operator.

"Line 1" + "line 2" // The result of folding two lines will be "string 1 line 2"

Type conversion

In order to convert the type into a string, for example, a reference to the directory element, the number and so on, it is enough to use the "Row ()" function. Functions similar to "COPLP ()" will also convert the variables into the string, but immediately with the cutting off of insignificant characters.

Row (1000) // returns "1,000"

Please note that when converting a number into a string, the program automatically added a space separating a thousand. In order to avoid this, you can use the following structures:

Strust (line (1000), symbols. NPP, "") // Return "1000"

Row (format (1000, "CG \u003d")) // Return "1000"

Quotes in string

Quite often, you will have to deal with the need to specify in a string variable quotation. It can be like a query text written in the configurator and just a variable. To solve this task, you just need to install two characters of quotes.

Title \u003d Row ("LLC" "Horn and hooves" "- this is us!") // Retain "Rog and Hortal LLC" - this is us! "

Multi-line, row transfer

In order to create a multi-line text, it is enough to add to it to transfer the string to it (symbols. PS).

Multi-lineCext \u003d "First Line" + Symbols. FS + "Second String"

How to remove gaps

In order to remove the gaps on the right or on the left, you can use the function "COPLP ()" (as well as "Sokrel ()" and "Cropp ()"):

Rangebesproelov \u003d Coolp ("Many letters") // Function will return the value "Many letters"

If after the transformation of the number in the string you needed to remove inseparable gapsTake advantage of the next design:

StringBebones \u003d Strust (string (99999), symbols. NPP, "") // Retain "99999"

Also, programmers often enjoy the following design, which allows you to delete, or replace all the spaces of the text variable to another symbol:

StringBezf belts \u003d Strust ("PR and V E T", "", "") // Retain "Hi"

Comparison of strings among themselves

You can compare the deadlines in the usual sign of equality. When compared, the register is taken into account.

"Hello" \u003d "Hello" // will return a lie
"Hello" \u003d "Hello" // Return Truth
"Hello" \u003d "Goodbye" // will return a lie

Mechanisms for working with rows in requests 1C little. First, the lines can be folded. Secondly, you can take a substring from the string. Thirdly, the lines can be compared, including the pattern. That's probably everything you can do with rows.

Addition string

For folding rows, the "+" operation is used in the query. You can add only limited length strings.

Choose "Name:" + Counterparties. Promotion as column1 from Directory. Contrgents as counterparties where counterparties. Link \u003d & Link

Function substring

Substring (<Строка>, <НачальнаяПозиция>, <Длина>)

Analog environment () function object model. The function of the substring () can be applied to the data of a string type and allows you to allocate a fragment <Строки> starting with symbol number <НачальнаяПозиция> (characters in the row are numbered from 1) and length <Длина> Symbols. The result of the calculation of the function has a string type of variable length, and the length will be considered unlimited if <Строка> has an unlimited length and parameter <Длина> It is not a constant or exceeds 1024.

If the length of the string is less than indicated in the second parameter, the function will return an empty string.

Attention! Using the substring function () in order to bring the strings of an unlimited length to limited length strings is not recommended. Instead of it, it is better to use the operation of bringing the type to express ().

Function like

If you need to make sure that the string props corresponds to certain criteria we compare it:

Choose counterparties. Appointment as a column1 from the reference book. Contrants as counterparties where counterparties. Name \u003d Gazprom

And what if need more cunning comparison? Not just on equality or inequality, but on the similarity of a specific template? That's just for this, a function is created like.

Like - the operator check the string on the like pattern. Analog Like in SQL.

The operator like that allows you to compare the value of the expression specified to the left of it, with the string of the template specified on the right. The value of the expression must have a string type. If the value of the expression satisfies the template - the result of the operator will be truth, otherwise - a lie.

The following characters in the template string are service and make sense other than the string symbol:

  • % (percentage): a sequence containing any number of arbitrary characters;
  • _ (underscore): one arbitrary symbol;
  • [...] (in square brackets one or more characters): any single character from listed inside square brackets. The lists may occur the ranges, for example A-Z, meaning an arbitrary symbol included in the range, including the ends of the range;
  • [^ ...] (In square brackets, the denial icon followed by one or more characters): any single character, except those listed in the negation icon.

Any other character means itself and does not carry any additional load. If one of the listed characters should be written as itself, then he must precede<Спецсимвол>. Self<Спецсимвол> (any suitable symbol) is defined in the same operator after keywords Specialist.

Part 1. Methods (26).

1.1. Basic methods (10). Independent, built on their simple algorithms.

Still () (addition to the right-on-left specified characters).

Page_invers () (Inversion - Symbols to the right on the left).

Page_Koda () (symbol codes through "," and an array with codes)

Page_Simol () (line from codes through "," or from an array with codes)

PRESSIVEMIVERS () (replacement of some characters to others).

Page_Ismassive () (line from the array of fragments through the separator)

Page_night () (Search for substring (including right) with decree. The entry number).

Page_NETIGR () (Search for a group of characters included in the specified character set)

Page_Nighting () (Search for a number, including on the right with the specified entry number)

Page_ interpret () (in an array, according to the established syntax)

1.2. Derived methods (12). Actually, this is the use of four generalized algorithms (see Part 2)

Page_) () (from the beginning and from the end of the line, not "afraid of" non-evil characters.

Page_Nighty () (search for substring (including without registering the register and right) with decree entering the entry).

Pricing () (Search (incl. Excluding the register and right), and replace the substring substrates).

Pagencons () (a piece of string between the specified separator entry (left or right)).

PRIVE REMOVER () (replacement in the source line "Slice" to the specified string).

Page_VMASSIV () (between the specified divider entry (including on the right and without the register).

Page_SenetosLogs () (split "Hard" to the substring, with a hyphen).

Page_PenetPoslov () (split "softly" to substring)

PRIVE () ("cut" to the substring of the specified lengths)

PR_TSOKRL () (replace the lion. A group of "reduced" characters on the "replacement string"

P_SOCP () (Replace rights. A group of "reduced" characters on the "replacement string"

PR_SOKRS () (replace in the middle of a group of "reduced" characters to the "Row of Replacement"

Page_Stiver (expansion to decree. Length by increasing the number of specified characters)

1.3. Detailed methods (3). "Preparation" strings with transfer to a table with detailed information.

Page_Tablvch () (in the table according to the system of nested separators).

Page_Tubngr (in a table according to a multi-level filter).

Page_Tabbone (in a table with numbers and fragments between them).

Part 2. Generalized methods of algorithms (3).

Page_name () (methods "find" and "replace").

Page_phragments () ("Slice" methods, "replaced," Wamissive "," Blubvch ").

Page_SOKR () ("Sokrel" methods, "Copp", "Sokres", "Expand".

Page_Match () (Methods "Transfers", "Transfers", "cut").

Part 3. Universal function.

This is a kind of conditional software interface that allows

apply several methods to the string at once. Implemented in the form

functions with seven parameters ("demo" built on this function):

Page_ (Methods, Layouts, Input, Param1, Param2, Length_Production, Dop Vode)

Parameters:

- "Methods" - a few "combined" and (or) one "monopoly" method

(single-spray codes or names, can be through ",")

- "Attamies" - a few "combined" and (or) "monopoly" options

"Monopoly" method (single-spray codes or titles);

- "Login" - line, or an array or table of values;

- "Param1" - a search string, replacement, separators, filters;

- "Param2" - a replacement string or symbols;

- "Length_Neor_Position" - 1, numbers through a separator or an array with numbers;

- "Dop post" - a number or string or an array or table of values;

Names and / or single-plating codes of methods of beams, as well as numbers in

(Length_Enumber_Position) can be in any register and separated

any of the following separators: ",:;".

Part 4. Some examples.

Essential \u003d (Page_Nighting (Vhstroka)<>Undefined);

Predicate \u003d (page_Nightigr (Vhstroka, "+ 0123456789")\u003e 0);

There is a wallinity \u003d (PR_NATIGR (VKSTR, PR_ Interpret ("LL"))\u003e 0);

There are indicators \u003d (page_nantigr (Bhstr, "+ to Rogu.0R9")\u003e 0);

Non-tyographic \u003d (PR_NETIGR ("- L-L-P-P-P-Z-C"))\u003e 0);

Part 5. Conclusion.

Where perhaps it was one pass along the line. The second pass is usually already fragmented. I did not use the built-in feature function ().

Used built-in functions: lion (), right () media (), stondin ()

- (Positioning and receiving part of the line - all be "fast").

Implemented in version 8.3.6.1977.

We expanded a set of functions designed to work with rows. We did it in order to give you more advanced tools for parsing the string data. New features will be convenient and useful in technological tasks for analyzing text. In tasks associated with text analysis, which contains data in a formatted form. This may be the analysis of some files received from equipment, or, for example, an analysis of the technological log.

All actions that perform new features you could perform before. With the help of more or less complex algorithms written in the embedded language. Therefore, new features do not give you some fundamentally new opportunities. However, they allow you to reduce the number of code, make the code easier and understandable. And besides, they allow you to speed up the implementation of actions. Because the features implemented in the platform work, of course, faster than a similar algorithm written in the embedded language.

Starry formatting function ()

This feature substitutes the parameters in the string. The need for such a transformation often occurs, for example, when displaying warning messages. The syntax of this feature is as follows:

Strarb (<Шаблон>, <Значение1-Значение10>)

<Шаблон> - This is a string in which you want to substitute the representation of the parameters.

<Значение1> , ... <Значение10> - These are the parameters (maximize - ten), which must be substituted into the string.

To specify a specific place in the template in which the substitution needs to be performed, you need to use the view markers% 1, ...% 10. The number of markers involved in the template and the number of parameters containing values \u200b\u200bmust match.

For example, the result of the execution of such an operator:

there will be a string:

Error in data in line 2 (type required)

Function working with string strings ()

This feature compares two lines without registering. For example, so:

The same action you could accomplish before using the comparaneise object:

However, the use of a new function looks simpler. And besides this, the function, in contrast to the object of comparison, works in thin clientand in the web client.

The functions of working with rows are routing (), stronckant ()

These functions are determined whether the string begins with the specified substring, whether the string of the specified substrate ends. The algorithm of these functions is easy to implement in the embedded language, but their presence allows you to write a cleaner and understood code. And they work faster.

For example, it is convenient to use them in the statement if:

Work functions with strings to line (), plug ()

These functions separate the string on the part according to the specified separator. Or, on the contrary, connect several rows into one, inserting the selected separator between them. They are convenient to create or analyze logs, technological magazine. For example, recording a technological log You can easily disassemble on parts suitable for further analysis:

Work function with strnet string ()

Instead of the old function, find () we implemented new featurewhich has additional features:

  • Search in different directions (from the beginning, from the end);
  • Search from the specified position;
  • Search for entry with the specified number (second, third, etc.).

In fact, it duplicates the capabilities of the old function. So done in order to maintain compatibility with modules compiled in older versions. An old function to find () is recommended no longer use.

Below is an example using new search capabilities. The search in the opposite direction is convenient when you need the last fragment of the formalized string, for example, full name File in URL. And the search from the specified position helps in cases where you need to search in a well-known fragment, and not throughout the row.