Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > String

Reply
Thread Tools

String

 
 
magix
Guest
Posts: n/a
 
      05-21-2008
Hi,

If I have string like below:
InputString= "@123456^BILL GATES^APR-2011 ?"

where @ - Start Character
^ - Separator
? - End Character

and it contains ID, NAME, and DATE

Pseudocode:

char * ID;
char * NAME;
char * DATE;

if ( (start char is @) AND (End Char is ?) AND (There are two ^ in string))
Then
{ //This is valid string

strncpy(ID, &InputString[1], 6); // ID has fix length
ID[6] = '\0'; // terminate the string

strncpy(NAME, &InputString[8], (Length of variable NAME Length) );
// NAME has variable length, but it is between two ^
NAME[strlen(NAME)] = '\0'; // terminate the string

strncpy(DATE, &InputString[position after the 2nd ^], (Length of
date between 2nd ^ and ?)); // Date is between 2nd ^ and ?
DATE[strlen(DATE)] = '\0'; // terminate the string
}

can help to transform into code (some string functions..i'm not too sure to
achieve and finding the length /position) ? Many thanks.

Regards.


 
Reply With Quote
 
 
 
 
Peter Nilsson
Guest
Posts: n/a
 
      05-21-2008
"magix" <(E-Mail Removed)> wrote:
> Hi,
>
> If I have string like below:
> InputString= "@123456^BILL GATES^APR-2011 * * * *?"
>
> where @ - Start Character


[Note that @ need not be a character in the basic
execution character set.]

> * * * * * ^ *- Separator
> * * * * * *? - End Character
>
> and it contains ID, NAME, and DATE
>
> Pseudocode:
>
> *char * ID;
> *char * NAME;
> *char * DATE;
>
> if ( (start char is @) AND (End Char is ?) AND (There are two ^ in string))
> Then
> { * *//This is valid string
>
> * * * * strncpy(ID, &InputString[1], 6); * *// ID has fix length
> * * * * ID[6] = '\0'; * *// terminate the string
>
> * * * * strncpy(NAME, &InputString[8], (Length of variable NAME Length) );
> // NAME has variable length, but it is between two ^
> * * * * NAME[strlen(NAME)] = '\0'; // terminate the string
>
> * * * * strncpy(DATE, &InputString[position after the 2nd ^], (Length of
> date between 2nd ^ and ?)); *// Date is between 2nd ^ and ?
> * * * * DATE[strlen(DATE)] = '\0'; // terminate the string
>
> }
>
> can help to transform into code (some string functions..i'm not too sure to
> achieve and finding the length /position) ? Many thanks.


Untested...

const char *pc1, *pc2, *pcm;

if ( InputString[0] == '@'
&& (pc1 = strchr(InputString + 1, '^')) != 0
&& pc1 - &InputString[1] == 6
&& (pc2 = strchr(++pc1, '^')) != 0
&& (pcm = strchr(++pc2, '?')) != 0
&& pcm[1] == 0)
{
strncpy(ID, InputString + 1, 6);
ID[6] = 0;

strncpy(NAME, pc1, pc2 - pc1 - 1);
NAME[pc2 - pc1 - 1] = 0;

strncpy(DATE, pc2, pcm - pc2);
DATE[pcm - pc2] = 0;
}

--
Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'System.String[]' from its string representation 'String[] Array' =?Utf-8?B?UmFqZXNoIHNvbmk=?= ASP .Net 0 05-04-2006 04:29 PM
Is "String s = "abc";" equal to "String s = new String("abc");"? Bruce Sam Java 15 11-19-2004 06:03 PM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 3 12-05-2003 04:20 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM



Advertisments