strcounter

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Text/Strs/Chars/Links
Introduced first in SolidGeometry 4.9, Creation date: 2020-03-30, Last change: 2025-09-14

detects an integer number at the end of a string and increments it

Description

Auxiliary function to manage file sequences for example

See Also: filenameinc

Example Illustration

 missing image of strcounter(fn,step)

Syntax

[fni,ostr,cstr]=strcounter(fn,[step])

Input Parameter

fn: original string
step: step size

Output Parameter

fni: new string name
ostr: original numbered string
cstr: changed numbered string

Examples


[a,b,c]=strcounter('AIM_LEC_02_SLIDE_05 INCL SOUND.avi')
strcounter('X345X123 ist ein TestA-100',-1)
strcounter('X345X123 ist ein TestA-99')
strcounter('X345X123 ist ein TestA-0099')
strcounter('X345X123 ist ein TestA-0000',-1)
strcounter('X345X123 ist ein TestA-100',-4)




Copyright 2020-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, strcounter, is designed to detect an integer at the end of a string and increment it by a specified step size. It is useful for managing file sequences.

Input Parameters

Output Results

Algorithm Steps

  1. Retrieve the step size from the input parameters, defaulting to 1 if not specified.
  2. Determine the length of the input string fn.
  3. Identify the position of the last numeric character in the string.
  4. Separate the string into two parts: the non-numeric prefix and the numeric suffix.
  5. If no numeric suffix is found, return an empty string for fni.
  6. Convert the numeric suffix to a number, increment it by the step size, and check if the result is negative.
  7. If the incremented number is negative, return an empty string for fni.
  8. Format the incremented number to maintain leading zeros and concatenate it with the non-numeric prefix.
  9. Return the new string fni, the original string ostr, and the incremented numeric part cstr.

Example Usage

Algorithm explaination created using ChatGPT on 2025-08-19 07:52. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21