Code Monkey home page Code Monkey logo

fisothemes / twincat-dynamic-string-kit Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 1.0 1.28 MB

A library that provides tools for working with dynamic strings in TwinCAT. It includes a comprehensive string builder with string enumeration and a read-only string builder adapter. Additionally, there are several C-style string functions, such as strstr(...), strlcpy(...), isspace(...), and more.

License: MIT License

automation beckhoff iec61131-3 plc string-builder string-manipulation toolkit twincat

twincat-dynamic-string-kit's Introduction

TwinCAT Dynamic String Kit

A library that provides tools for working with dynamic strings in TwinCAT. It includes a comprehensive string builder with string enumeration and a read-only string builder adapter. Additionally, there are several C-style string functions, such as isdigit(...), strstr(...), strlcpy(...), isspace(...), and more. There are also functions for converting ANY to STRING and STRING to ANY.

Examples

Working with the string builder.

Declarations:

VAR
	bStart 			: BOOL;
	nLn1, nLn2 		: T_Size;
	sValue1, sValue2	: STRING(255);
	pString			: POINTER TO STRING;
	fbStringBuilder1,
	fbStringBuilder2	: FB_StringBuilder;
END_VAR

Implementation:

IF bStart THEN
	bStart := FALSE;
	fbStringBuilder2
		.Append(' I hate cats.')
		.GetBuffer(pString);
	
	fbStringBuilder1
		.Clear()
		.Append(' I love cats.')
		.Append(' I love dogs.')
		.AppendBuffer(pString)
		.BTrim()
		.GetLength(Length => nLn1)
		.Replace('cats','dogs',TRUE)
		.Insert(nLn1, ' Anaconda! ')
		.Split(nLn1,100, fbStringBuilder2.Append(' Tigers are cats.'))
		.GetLength(Length => nLn1);
	
	sValue1 := fbStringBuilder1.ToUppercase().GetString();
	sValue2 := fbStringBuilder2
		.ToLowercase()
		.BTrim()
		.GetString();
	
	nLn2 := Tc2_Standard.LEN(sValue1);
	__DELETE(pString);
	END_IF

Output:

string builder


Working with the read-only adapter.

Declarations:

VAR
	bStart			: BOOL;
	sValue 			: STRING(255);
	nPos			: T_Size;
	tTime 			: TIME :=  TIME();
	tTime2			: TIME;
	fbStringBuilder 	: FB_StringBuilder;
	fbReadOnlySB 		: FB_ReadOnlyStringBuilderAdapter;
	ipReadOnlySB 		: I_ReadOnlyStringBuilderAdapter;
END_VAR

Implementation:

fbReadOnlySB(ipStringBuilder := fbStringBuilder);
ipReadOnlySB := fbReadOnlySB;

IF bStart THEN
	bStart := FALSE;
	fbStringBuilder
		.Clear()
		.Append('   I love cats.')
		.Append('The time is: ').AppendAny(tTime).Append('.')
		.Append('   ')
		.BTrim();
	END_IF

sValue := ipReadOnlySB
	.Search('T#', 0, Position => nPos)
	.CopySubstringTo(nPos, tc2_Standard.LEN(TO_STRING(tTime)), tTime2)
	.GetString();

Output:

string builder using an adapter


Working with the enumerator.

Declarations:

VAR
	bStart			: BOOL;
	sValue			: STRING(255);
	dtTime			: DT :=  DT#2023-5-8-12:55:23;
	fbStringBuilder1,
	fbStringBuilder2	: FB_StringBuilder;
	ipEnumerator		: I_Enumerator;
END_VAR

Implementation:

IF bStart THEN
	bStart := FALSE;
	
	fbStringBuilder1
		.Clear()
		.Append('   I love cats.')
		.Append('The time is: ').AppendAny(dtTime).Append('.')
		.BTrim();
	
	ipEnumerator := fbStringBuilder1.GetEnumerator();
	WHILE ipEnumerator.Next() DO
		fbStringBuilder2.Append(ipEnumerator.Current);
		END_WHILE
		
	sValue := fbStringBuilder2.GetString();
	END_IF

Output:

string builder enumerator

⚠ Important ⚠

This project is still in development. There's a lot of work and testing ahead. Changes to functionality may occur in the future.

twincat-dynamic-string-kit's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

uwence

twincat-dynamic-string-kit's Issues

Generate .library

This is more a suggestion. You could generate the .library, so it's easy to import and upgrade.

Thanks for the great work

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.