NO

Author Topic: string - to grap some of its content  (Read 3120 times)

magic

  • Guest
string - to grap some of its content
« on: September 22, 2008, 10:49:18 PM »
Is there a library to manipulate a string like in BASIC language. For example..

LEFT("test",2)  ==> return "te"
RIGHT("test",2) ==> return "st"
MID("test",2,1) ==> return "e"

Sorry if this off the way to program in C. I from BASIC background try to learn C.
I found that the library given is quite limited. I know C is power but I wonder how
did people actually do to program with those small amount of library.

I figure they probably use those preset dll on window like User32 kernel32 ect...
But still difficult to find a function like LoadJPG("name.jpg").

I see here that internet very important. I have to dig into MSDN for a usefull function
and still cannot easily found FloadToString() function..

Is this really the scenario or its just me. Please advice me how to learn C in the
best way. I will try hard to learn C or C++ because I know its a real kicking language.

CLR

  • Guest
Re: string - to grap some of its content
« Reply #1 on: September 23, 2008, 01:00:40 AM »
Hello magic.

Welcome.

You should start thinking in C. Try http://www.google.com/search?q=c+language+tutorial

Once you know how it works, you can play with Windows Programming:
http://www.winprog.org/tutorial/


Offline DMac

  • Member
  • *
  • Posts: 272
Re: string - to grap some of its content
« Reply #2 on: September 23, 2008, 01:05:21 AM »
There is not a basic style string handling library.

However BCX, the Basic to C translator is a great way to learn C and contains lots of examples.  Write what you want to do in BCX and then run the translator and look at the C code generated.

I have adapted some BCX constructs for use in my C programs that handle lots of text.

Here are some examples:

Code: [Select]
/*
*
*     FUNCTION: BCX_TmpStr
*
*     PURPOSE:  Provide temporary strings from a curcular storage array.
*
*     PARAMS:   size_t Bites - desired length of string
*
*     RETURNS:  LPSTR - pointer to the allocated temporary string
*
* History:
*                March '07 - Borrowed from BCX
*
*/

LPSTR BCX_TmpStr (size_t Bites)
{
     static int   StrCnt;
     static LPSTR StrFunc[2048];
     StrCnt=(StrCnt + 1) & 2047;
     if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);
     return StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));
}

/*
*
*     FUNCTION: Mid
*
*     PURPOSE:  Extract a substring from a given source string
* based on character start position in source string
*               and an optional length.
*
*     PARAMS:   LPSTR lpSource - pointer to source string
*               INT start - start position
*               INT length - optional length of sub string
*
*     RETURNS:  LPSTR - extracted sub string
*
* History:
*                March '07 - Borrowed from BCX
*
*/

LPSTR Mid (LPSTR, INT, INT=-1);
LPSTR Mid (LPSTR lpSource, INT start, INT length)
{
     register int tmplen = strlen(lpSource);
     LPSTR strtmp;
     if(start>tmplen||start<1) return BCX_TmpStr(1);
     if (length < 0) length = tmplen - start + 1;
     strtmp = BCX_TmpStr(length);
     return (LPSTR)memcpy(strtmp,&lpSource[start-1],length);
}

LPSTR Left (LPSTR mainStr, UINT length)
{
     return Mid(mainStr,1,length);
}

LPSTR Right (LPSTR mainStr, UINT length)
{
     return Mid(mainStr,strlen(mainStr)-length+1,-1);
}
No one cares how much you know,
until they know how much you care.