LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Remove a Carriage Return from a string in CVI

I have the following string in CVI/Labwindows:

Sat Apr 20, 2005 20:00:00 CR


Is there a way to manipulate the string to remove the CR????
0 Kudos
Message 1 of 5
(4,925 Views)
Sure.
Supposing you want to keep the first characters of the string, simply set string[n-1] = 0: this terminates the string discarding all that follows.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 5
(4,914 Views)
I have made a simple routine which deletes all space characters (spaces, new lines, CR etc) from the end of a line.
Can come in handy for this problem, but also for some future need.

Good luck!

int StringDeleteSpaceAtEnd(char *String)
{ int StrLen, i;
// deletes spaces, newlines, tabs etc at the end of a string
// returns the remaining stringlength
if (!String) return 0;
StrLen = strlen(String); if (!StrLen) return 0;
for (i=StrLen-1; i>=0; i--) {
if (isspace(String[i])) String[i] = 0;
else return (i+1);
}
return 0;
}
Message 3 of 5
(4,902 Views)

You can use:

 

strncpy(STR_TARGET,STR_SOURCE,strlen(STR_SOURCE)-2);

 

The function strncpy delete the latest 2 bytes of STR_SOURCE

0 Kudos
Message 4 of 5
(4,294 Views)

jjvema ha scritto:

You can use:

 

strncpy(STR_TARGET,STR_SOURCE,strlen(STR_SOURCE)-2);

 

The function strncpy delete the latest 2 bytes of STR_SOURCE


Take care when using strncpy as this command does not terminate the copied string: you should add STR_TARGET[strlen(STR_SOURCE)-2] = 0; or better use the toolbox function StrinCopyMax which has a series of advantages highlighted in the online help.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 5
(4,271 Views)