Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Manipulating strings [solved]

Manipulating strings [solved] 15 years 7 months ago #305

  • Ohl
  • Ohl's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 102
  • Karma: 3
Hi,

I have a signal variable of type [string], containing a filname including the path to the file. I would like to extract the filename and store it in another signal variable.

The string functions includes SubStr but since my original string may vary in length I need to find the position of the last slash (/) character.

I have looked at the DataArithm object but have not yet figured out if this is the right tool.

Any advices are welcome.

/Ohl

Post edited by: Ohl, at: 2008/09/02 12:21
The administrator has disabled public write access.

Re:Manipulating strings 15 years 7 months ago #310

  • claes
  • claes's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 3177
  • Thank you received: 502
  • Karma: 133
Hello,

Yes you have to use DataArithm and connect both the source and target string objects to the DataArithm with GetData objects.

The code in the DataArithm would be something like
this if you connect the source to Da1 and the target to Da2

[code:1]classdef Da1 Sv;
classdef Da2 Sv;
char *s;

if ( (s = strrchr ( Da1->ActualValue, '/')))
strcpy( Da2->ActualValue, s+1);
[/code:1]

/Claes
The administrator has disabled public write access.

Re:Manipulating strings 15 years 7 months ago #311

  • Ohl
  • Ohl's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 102
  • Karma: 3
Tanks!

It worked \"right out of the box\"!

Regards
Ohl
The administrator has disabled public write access.

Re:Manipulating strings 15 years 7 months ago #312

  • robert
  • robert's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 178
  • Karma: 7
Observe that strrchr return NULL if no occurence of the character is found and no copy to Da2 will be made.
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 9.352 seconds