Truncating Text Without Conditional Checking in ZennoPoster?

Pierre Paul Jacques

Активный пользователь
Регистрация
08.10.2023
Сообщения
134
Благодарностей
35
Баллы
28
Hello Zenno Friends,

I am currently working with ZennoPoster and facing a scenario where I need to truncate text to a maximum of 3000 characters.
( i want to stay in the limit of Opean AI api,)

I am using the Substring function as per the documentation. However, I encounter an error when the text to be truncated is shorter than 3000 characters. If the text is longer than 3000 characters, the function works perfectly, truncating the text to 3000 characters.

I am looking for a way to achieve the truncation in a single action/block within ZennoPoster without having to first check the text's length with a conditional statement. The goal is to have a streamlined solution that can handle the text irrespective of its initial length.

Is there an alternative action or a way to use Substring (or a similar function) in ZennoPoster that can elegantly handle this scenario without requiring a preceding conditional check on the text length?

I appreciate any guidance or suggestions on how to accomplish this.
Thank you in advance!
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113
Am I understanding this right, and your problem is, making two logical actions into one zenno cube?
If so, learn C#
 
  • Спасибо
Реакции: Pierre Paul Jacques

Pierre Paul Jacques

Активный пользователь
Регистрация
08.10.2023
Сообщения
134
Благодарностей
35
Баллы
28
Am I understanding this right, and your problem is, making two logical actions into one zenno cube?
If so, learn C#
Thank again Lokiys!

Yes i like to have my template the more minimalist : less block and arrow of condition,
so you right C# Sharp is the best option:


And thanks to GPT : i got this code :



Truncate with condition:
// Get the text from the variable C_Scrap_1_Page
string text = project.Variables["C_Scrap_1_Page"].Value;

// Check if the length of the text exceeds 3000 characters
if (text.Length > 3000)
{
    // If yes, truncate the text to 3000 characters
    text = text.Substring(0, 3000);
}

// Set the truncated text (or the original text if its length was less than 3000 characters) back to the variable C_Scrap_1_Page
project.Variables["C_Scrap_1_Page"].Value = text;
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113
Good luck with learning c# :-)
Small note, you can convert actions to c# and see how they work behind the scenes. Not available for all actions, though.
113731
 
  • Спасибо
Реакции: Pierre Paul Jacques

Alexmd

Client
Регистрация
10.12.2018
Сообщения
1 022
Благодарностей
1 424
Баллы
113
Zennoposter already has the "Truncate" method...
C#:
return project.Variables["C_Scrap_1_Page"].Value.Truncate(3000);
to use this C# code check the checkbox from "C# action settings" and select a variable to return data to
 
  • Спасибо
Реакции: Pierre Paul Jacques

Pierre Paul Jacques

Активный пользователь
Регистрация
08.10.2023
Сообщения
134
Благодарностей
35
Баллы
28
Zennoposter already has the "Truncate" method...
C#:
return project.Variables["C_Scrap_1_Page"].Value.Truncate(3000);
to use this C# code check the checkbox from "C# action settings" and select a variable to return data to
Thank Alek your code, its works!
And the good thing with it i don't need to make the conditions,
your are more efficient than GPT 4 ;-)
 

Pierre Paul Jacques

Активный пользователь
Регистрация
08.10.2023
Сообщения
134
Благодарностей
35
Баллы
28
Good luck with learning c# :-)
Small note, you can convert actions to c# and see how they work behind the scenes. Not available for all actions, though.


Thank for the tips,
C# looks like a powerfull joker for Zenno!

And you right the convert is not available for all the action,
i wanted to try it with "If" action and is not possible.


113739



In fact i try with the "If" to make a condition if the text of my variable got <h2> inside,but i didn't suceed...
i guess the if need the exact value of this texte and not a part of it.
It's worked with texte processing and the option "Error When the Answer is Empty" like i can have the "true" and "false

113740



Have a great Sundays!
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)