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
- fn: The original string that potentially ends with a number.
- step: The step size by which the detected number is incremented. It is optional and defaults to 1 if not provided.
Output Results
- fni: The new string name with the incremented number.
- ostr: The original string up to the detected number.
- cstr: The replaced chain, which is the incremented number part.
Algorithm Steps
- Retrieve the step size from the input parameters, defaulting to 1 if not specified.
- Determine the length of the input string
fn
.
- Identify the position of the last numeric character in the string.
- Separate the string into two parts: the non-numeric prefix and the numeric suffix.
- If no numeric suffix is found, return an empty string for
fni
.
- Convert the numeric suffix to a number, increment it by the step size, and check if the result is negative.
- If the incremented number is negative, return an empty string for
fni
.
- Format the incremented number to maintain leading zeros and concatenate it with the non-numeric prefix.
- Return the new string
fni
, the original string ostr
, and the incremented numeric part cstr
.
Example Usage
[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)
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