Contacts

1C Employment Substring in the string. New features working with rows. Work function with strnet string ()

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 (<Строка>, <НачальнаяПозиция>, <Длина>)

Analogue of the media function () from the 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 defined 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.

Notes from the cast Caster

08/18/2014 New working functions with rows

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 more or less complex algorithmswritten 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 perform before using the object Comparison:

However, the use of a new function looks simpler. And besides this feature, unlike the object Comparison, Works in the thin client, and 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 operator If a:

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 an old function To find() We have 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. Old feature To find() It 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, the full file name in the 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.

Lines in 1C 8.3 in the built-in 1c language are primitive-type values Line. Values this type Contain a string in unicode format of arbitrary length. String variables are a set of enclosed characters in quotes.

Example 1. Create a string variable with text.

Row-free \u003d "hello world!";

Functions of working with lines in 1C 8.3

This section will contain basic functions that allow you to change the lines in 1C, or analyze the information contained in them.

Strotina

Strdlin (<Строка>) . Returns the number of characters contained in the string transmitted in the parameter.

Example 2. Calculate the number of characters in the "Hello world!" String.

Row \u003d "Hello the world!"; Martensumless \u003d stondin (string); Report (summons);

The result of the execution of this code will be displaying the number of characters of the string: 11.

Sokrel

Sokrel (<Строка>) . Cuts out of insignificant characters to the left of the first meaning symbol in the row.
Unignless symbols:

  • space;
  • non-exempt space;
  • tabulation;
  • return carriage;
  • line translation;
  • translation of form (pages).

Example 3. Remove all spaces on the left side of the line "World!" And attach to it the line "Hello".

Line \u003d Sokrel ("Peace!"); Row \u003d "hello" + line; Report (string);

The result of the execution of this code will be output to the screen "Hi Mir!".

Socrp

Copp (<Строка>) . Cuts out of insignificant characters to the right of the first meaning symbol in the row.

Example 4. To form from the Row "Hi" and "Peace!" phrase "hello world!"

Row \u003d Cropp ("Hi") + "" + Sokrel ("Peace!"); Report (string);

SokrLP

SokrLP (<Строка>) . Cuts out of insignificant characters to the right of the first meaning symbol in the row, also cuts out of insignificant characters to the left of the first meaningful character in the row. This feature It is used more often than the previous two, as it is more universal.

Example 5. Remove insignificant characters standing on the left and right in the name of the counterparty.

Counterparty \u003d References. Proteces. Enti-moving ("INN", "0777121211"); Counterparty \u003d Counterparty. PREPARY OBJECT (); Counterparty. Name \u003d Coolp (counterparty. Name); Counterparty. To recruit ();

a lion

A lion(<Строка>, <ЧислоСимволов>) . Gets the first string characters, the number of characters is indicated in the parameter Slovesmiths.

Example 6. Let in the structure Employee contain name, surname and middle name of the employee. Get a string with the surname and initials.

Initial data \u003d lion (employee. I mean, 1); Initiality \u003d lion (employee. Delicacy, 1); Fulfill \u003d employee.Familia + "" + initial and ".". " + Initiality + ".";

Right

Rights (<Строка>, <ЧислоСимволов>) . Receives the latest string symbols, the number of characters is indicated in the parameter Slovesmiths. If the specified number of characters exceeds the length of the line, then the entire string is returned.

Example 7. Let the Date in the format of "GGHHMDD" are recorded at the end of the string variable, to get a line with the date and convert it to the type date.

String \u003d " The current date: 20170910 "; Stricked \u003d Rights (string, 8); date \u003d date (strfewar);

Media

Environments (<Строка>, <НачальныйНомер>, <ЧислоСимволов>) . Gets a substring from the row transmitted in the parameter Linestarting with the character number of which is specified in the parameter Start-up and the length transmitted to the parameter Slovesmiths.The numbering of characters in the string begins with 1. If in the parameter Start-up The value is less or equal to zero, the parameter takes the value 1. If the parameter Nizalsimvol Not specified, then symbols are selected until the end of the line.

Example 8. Suppose that in the string variable, starting from the ninth position contains the region code, you should get it and write it into a separate string.

Line \u003d "Region: 99 Moscow"; Region \u003d media (string, 9, 2);

Strnet

Strnet<Строка>, <ПодстрокаПоиска>, <НаправлениеПоиска>, <НачальнаяПозиция>, <НомерВхождения>) . Searches for the specified substring in the string, returns the position number of the first character found substring found. Consider the parameters of this feature:

  • Line. Source line;
  • Substream. Desired substring;
  • Direction. Specifies the direction of searching the substring in the row. Can take values:
    • Direction;
    • Direction;
  • Stagnation. Specifies the position in the string from which the search begins;
  • Feedback. Indicates the entry number of the desired substring in the source line.

Example 9. In the line "Hello the world!" Determine the position of the last entry of the symbol "and".

DRIZE \u003d Strnet ("Hello Mir!", "And", direction from .Sconsion); Report (feeder);

The result of the execution of this code will be output to the screen number of the last entry of the symbol "and": 9.

Light

Vrega (<Строка>) . Converts all the characters of the specified string in 1C 8 to the top register.

Example 10. Transform the line "Hello Mir!" To the top register.

Rangered \u003d lag ("hello world!"); Report (rowing);

The result of the execution of this code will be output to the screen of the line "Hello the world!"

Nreg

Nrega (<Строка>) . Converts all the characters of the specified string in 1C 8 to the lower register.

Example 11. Transform a string "Hello Mir!" to lower register.

Strochanneg \u003d Nreg ("Hello Pee!"); Report (rowing);

The result of the execution of this code will be output to the screen of the line "Hello Peace!"

Treg.

Trega (<Строка>) . Converts a string as follows: The first symbol of each word is translated into the upper case, the remaining words of the word are translated into the lower register.

Example 12. Make the heads of the first letters of words in the line "Hello the world!".

Stinkateg \u003d Treg ("Hello Peace!"); Report (Stinkateg);

The result of the execution of this code will be output to the screen of the line "Hello Peace!"

Symbol

Symbol(<КодСимвола>) . Gets a symbol on its code in Unicod encoding.

Example 13. Add to the left and right to the line "Hello the world!" Symbol ★

String passages \u003d symbol ("9733") + "Hello world!" + Symbol ("9733"); Report (string passages);

The result of the execution of this code will be displayed on the screen of the string "★ Hi Peace! ★"

Kodsimvol.

Codeimvol (<Строка>, <НомерСимвола>) . Gets a symbol code in Unicode encoding from a string specified in the first parameter located in the position specified in the second parameter.

Example 14. Find out the code of the last symbol in the "Hi World!" Line.

Row \u003d "Hello the world!"; Codeimvol \u003d codeimvol (string, stringle (string)); Report (codeimvol);

The result of the execution of this code will be output to the symbol code "!" - 33.

Empty line

Empty line(<Строка>) . Checks whether the string is only from insignificant characters, that is, whether it is empty.

Example 15. Check whether the empty string consists of three spaces.

Empty \u003d mutted (""); Report (empty);

The result of the execution of this code will be output to the screen "Yes" (string expression of logical value True).

Strust

Strust (<Строка>, <ПодстрокаПоиска>, <ПодстрокаЗамены>) . Finds in the original line all the entries of the search substring and replaces it on the substitution substitution.

Example 16. In the line "Hello the world!" Replace the word "world" on the word "friends."

Row \u003d Strust ("Hello Mir!", "Mir", "Friends"); Report (string);

The result of the execution of this code will be output to the screen "Hi Friends!"

Strostroke

Strokelost (<Строка>) . Allows you to calculate the number of rows in a multi-line string. For the transition to new string 1C 8 uses a symbol PS. (string translation symbol).

Example 17. Determine the number of rows in the text:
"First line
Second string
Third line »

Number \u003d Strover Basket ("First Row" + Symbols. PC + "The second line" + characters. PC + "Third String"); Report (number);

The result of the execution of this code will be output to the number of rows in the text: 3

Plugulastrik

Plotchikstka (<Строка>, <НомерСтроки>) . Gets a string in a multi-line string by its number. Row numbering starts with 1.

Example 18. Get the last string in the text:
"First line
Second string
Third line »

Text \u003d "first line" + characters. PC + "The second line" + characters. FS + "Third Row"; Lastastright \u003d Plisproktriktka (text, strokelock (text)); Report (last time);

The result of the execution of this code will be output to the "Third Row" line screen.

Strirling

Strirling (<Строка>, <ПодстрокаПоиска>) . Returns the number of entries of the specified substring in the string. The function is sensitive to the register.

Example 19. Determine how many times it enters the string in 1C 8.3 and 8.2. The letter "C", regardless of its register.

Row \u003d "Rows in 1C 8.3 and 8.2"; Numerals \u003d label (lag (string), "C"); Report (numerals);

The result of the execution of this code will be outputting the number of entries: 2.

Scheduled

Rone (<Строка>, <СтрокаПоиска>) . Checks whether the string passed in the first parameter, from the row in the second parameter.

Example 20. Determine whether the INN of the selected counterpart is started with the number 1. Let in the variable Counterparty Counterparties.

Inn \u003d Counterparty.inn; Starts together \u003d RRINCED (INN, "1"); If it starts at the then // Your code ended;

Strazanacivna

Strasting (<Строка>, <СтрокаПоиска>) . Checks whether the string ended in the first parameter, on the line in the second parameter.

Example 21. Determine whether the Inn of the selected counterpart is ends to the figure 2. Let in the variable Counterpartystored link to the directory element Counterparties.

Inn \u003d Counterparty.inn; Endaged Valves \u003d Strasting (Inn, "2"); If you finish it then // Your code ended;

Strap

Strain<Строка>, <Разделитель>, <ВключатьПустые>) . Parts the string on the part according to the specified separator symbols and records the resulting strings into an array. In the first parameter, the source line is stored, in the second line containing the separator, in the third it is indicated whether to record empty lines to the array (by default True).

Example 22. Let we have a string containing the numbers separated by the ";" symbol, get an array of numbers from the string.

Row \u003d "1; 2; 3"; Array \u003d strap (string, ";"); For sch \u003d 0 by an array. Number () - 1 cycle attempt array [sch] \u003d number (CROLP (array [sch])); Exception array [sch] \u003d 0; Endropset endrequency;

As a result of execution, an array will be obtained with numbers from 1 to 3.

Stroke

Stroen<Строки>, <Разделитель>) . Converts an array of rows from the first parameter to the string containing all the elements of the array through the separator specified in the second parameter.

Example 23. Using an array of numbers from the previous example, to obtain the original string.

For sch \u003d 0 by an array. Number () - 1 cycle array [sch] \u003d string (array [sch]); EndCycle; Line \u003d stroke (array, ";");

The string is one of the primitive data types in 1C systems: Enterprise 8. Variables with type line contain text.

Values \u200b\u200bof type variables lineenclosed in double quotes. Several variables of this type can be folded.

Per1 \u003d "word 1";
Per2 \u003d "word 2";
Per3 \u003d per1 + "" + per2;

Eventually Per3. will be important Word 1 word 2 ".

In addition, in 1C systems: Enterprise 8 provides functions for working with lines. Consider the main:

Enters (<Строка>, <Подсказка>, <Длина>, <Многострочность>) — the function is designed to output a dialog box in which the user can specify the value variable type Line. Parameter <Строка> it is mandatory and contains the name of the variable in which the introduced string will be recorded. Parameter <Подсказка> optional is the title dialog box. Parameter <Длина> optional, shows maximum length Entered lines. The default is zero, which means unlimited length. Parameter <Многострочность> optional. Specifies the mode of entering multi-line text: Truth - Enter multi-line text with row separators; Lie - enter a simple line.

The string can be entered and, knowing the symbol code in the Enicode encoding:

Symbol(<КодСимвола>) — the code is entered as a number.

Letter \u003d symbol (1103); // I

There is also a reverse function that allows you to find out the code of any symbol.

Codeimvol (<Строка>, <НомерСимвола>) — returns the number of the specified symbol in the Unicode encoding in the form of a number.

Text register conversion functions:

Vrega (<Строка>) - Converts all string characters to the top register.

Nrega (<Строка>) - Converts all string characters to the lower case.

Trega (<Строка>) - Converts all string symbols in the title register. That is, the first letters in all words are converted to the upper case, and the remaining letters in the lower one.

Search and replace characters in the string:

To find(<Строка>, <ПодстрокаПоиска>) - Find the character number of the search for a search substring. For example:

Find ("String", "Oka"); // four

Strnet<Строка>, <ПодстрокаПоиска>, <НаправлениеПоиска>, <НачальнаяПозиция>, <НомерВхождения>) - Finding the character number of the search for the search substring, the entry number is indicated in the corresponding parameter. In this case, the search begins with a symbol whose number is specified in the parameter Installation.Search is possible from the beginning or from the end of the line. For example:

Number4 entry \u003d strnet ( "Death", "O", direction. First, 1, 4); // 7.

Strust (<Строка>, <ПодстрокаПоиска>, <ПодстрокаЗамены>) - Finds in the original line all the entries of the search substring and replaces it on the substitution of the replacement.

Strust ("String", "Oka", ""); // page

Empty line(<Строка>) - Checks the string for the presence of significant characters. If there are no meaningful characters, or there are no characters at all, then the value is returned True. Otherwise - False.

Strirling (<Строка>, <ПодстрокаПоиска>) - Calculates the number of occurrences of the search substrity in the source line.

Strirling ( "Study, study and study again", "to study" , "" ) ; // 3.

Strarb (<Строка>, <ЗначениеПодстановки1>…<ЗначениеПодстановкиN> — entends the parameters in the string by number. The string must contain form substitution markers: "% 1 ..% n". Numbering markers begins with 1. If the value of the parameter Undefined, empty string is substituted.

Strarb ( "Parameter 1 \u003d% 1, parameter 2 \u003d% 2", "1" , "2" ) ; // Parameter 1 \u003d 1, parameter 2 \u003d 2

Row conversion functions:

A lion(<Строка>, <ЧислоСимволов>) - Returns the first first string characters.

Rights (<Строка>, <ЧислоСимволов>) - Returns the latest string characters.

Environments (<Строка>, <НачальныйНомер>, <ЧислоСимволов>) - Returns a string in length in<ЧислоСимволов>starting with the symbol<НачальныйНомер>.

Sokrel (<Строка>) Cuts out of insignificant characters to the left of the first meaning symbol in the row.

Copp (<Строка>) - Cuts out of insignificant characters to the right of the last significant symbol in the string.

SokrLP (<Строка>) - Cuts out of insignificant characters to the left of the first meaning symbol in the row and to the right of the last significant symbol in the row.

Plotchikstka (<Строка>, <НомерСтроки>) - Gets a string of a multi-line string by number.

Other features:

Strdlin (<Строка>) - Returns the number of characters in the string.

Strokelost (<Строка>) - Returns the number of rows in a multi-line string. The string is considered new if it is separated from the previous row translation symbol.

Stresh (<Строка1>, <Строка2> ) - compares two lines without registering. Function works similarly to the object Comparison. Returns:

  • 1 - if the first line is greater than the second
  • -1 - if the second line is greater than the first
  • 0 - if rows are equal

Strike ("First Row", "Second String"); // one



Did you like the article? Share it