• Welcome to Theos PowerBasic Museum 2017.

Recent posts

#31
Discussion / Re: String::Remove(const TCHAR...
Last post by Patrice Terrier - June 29, 2017, 03:29:19 PM
Here is what i am using in my code for triming without using a dedicated string class...

long find_wchar(IN WCHAR* sChar, IN WCHAR* sItem) {
    long nRet = -1;
    long K = 0, nLen = lstrlen(sChar);
    for (K = 0; K < nLen; K++) {
        if (sChar[K] == sItem[0]) { nRet = K; }
    }
    return nRet;
}

void reverse(WCHAR str[], long length) {
    int start = 0;
    int end = length -1;
    while (start < end) {
        swap(*(str + start), *(str + end));
        start++;
        end--;
    }
}

WCHAR* RTRIM(IN WCHAR* sBuf, IN WCHAR* sChar) {
    long nLength = lstrlen(sBuf);
    long nLen = lstrlen(sChar);
    if ((nLength) && (nLen)) {
        while (nLength > 0) {
            nLength -= 1;
            if (find_wchar(sChar, &sBuf[nLength]) > -1) {
                sBuf[nLength] = L'\0';
            } else {
                break;
            }
        }
    }
    return sBuf;
}

WCHAR* LTRIM(IN WCHAR* sBuf, IN WCHAR* sChar) {
    reverse(sBuf, lstrlen(sBuf));
    sBuf = RTRIM(sBuf, sChar);
    reverse(sBuf, lstrlen(sBuf));
}

WCHAR* TRIM(IN WCHAR* sBuf, IN WCHAR* sChar) {
    return LTRIM(RTRIM(sBuf, sChar), sChar);
}

#32
Discussion / Re: String::Remove(const TCHAR...
Last post by James C. Fuller - June 29, 2017, 02:25:14 PM
Fred,
  This seems to work. Do you see any problems reusing s1?
James


typedef String fstring;
int _tmain ()
{
    fstring  s1(_T("Zero,  One, Two  , Three ,  Four, Five   , Six, Seven, Eight , Nine, Ten,"));
    s1.Print( true);
    s1 = s1.Remove(_T(" "));
    s1.Print( true);
    // Remove Trailing comma
    s1.RTrim(44);
    s1.Print( true);
}


output:

Zero,  One, Two  , Three ,  Four, Five   , Six, Seven, Eight , Nine, Ten,
Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,
Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten
#33
Discussion / Re: String::Remove(const TCHAR...
Last post by Frederick J. Harris - June 28, 2017, 08:36:47 PM
Wow!  That's cool.

Fred
#34
Discussion / Re: String::Remove(const TCHAR...
Last post by James C. Fuller - June 28, 2017, 08:08:03 PM
Fred,
  Ok. Thanks Fred.
  Funny you should mention the trims. Those are the ones I modified so as to come in line with the ones I use and am used to in bc9.
I added a parameter so you could trim any other single char.
James


changed in Strings.h:
[code]
  void LTrim(int charToTrim=32);                                                  // Removes leading white space by modifying existing String
  void RTrim(int charToTrim=32);                                                  // Removes trailing white space by modifying existing String
  void Trim(int charToTrim=32);                                                   // Removes leading or trailing white space from existing String

changed in Strings.cpp

void String::LTrim(int charToTrim)
{
size_t iCt=0;

for(size_t i=0; i<this->iLen; i++)
{
     if(this->lpBuffer[i]==9||this->lpBuffer[i]==10||this->lpBuffer[i]==13||this->lpBuffer[i]==32||this->lpBuffer[i]==charToTrim)
        iCt++;
     else
        break;
}
if(iCt)
{
    for(size_t i=iCt; i<=this->iLen; i++)
        this->lpBuffer[i-iCt]=this->lpBuffer[i];
}
this->iLen=this->iLen-iCt;
this->blnSucceeded=TRUE;
}

void String::RTrim(int charToTrim)
{
int iCt=0;

for(int i=this->iLen-1; i>0; i--)
{
     if(this->lpBuffer[i]==9||this->lpBuffer[i]==10||this->lpBuffer[i]==13||this->lpBuffer[i]==32||this->lpBuffer[i]==charToTrim )
        iCt++;
     else
        break;
}
this->lpBuffer[this->iLen-iCt]=0;
this->iLen=this->iLen-iCt;
this->blnSucceeded=TRUE;
}

void String::Trim(int charToTrim)
{
this->LTrim(charToTrim);
this->RTrim(charToTrim);
this->blnSucceeded=TRUE;
}


#35
Discussion / Re: String::Remove(const TCHAR...
Last post by Frederick J. Harris - June 28, 2017, 06:24:22 PM
Now, interestingly enough, or strangely enough, my String::Trim(), String::LTrim(), and String::RTrim() don't behave like that.  They alter the existing object.  Here is an example showing that...


// cl Test03.cpp Strings.cpp /O1 /Os /GR- /GS- TCLib.lib kernel32.lib user32.lib
#define UNICODE
#define _UNICODE
#include <windows.h>
#include "stdio.h"
#include "Strings.h"

int main()
{
String* pStrs=NULL;
int iCnt=0;
String s;

s=L"  one ,  two  ,  three,  four ,  five    ,   six";
s.Print(true);
iCnt=s.ParseCount(L',');
pStrs=new String[iCnt];
s.Parse(pStrs,L',',iCnt);
for(size_t i=0; i<iCnt; i++)
     pStrs[i].Print(false);
printf("\n");
for(size_t i=0; i<iCnt; i++)
{
     pStrs[i].Trim();
     pStrs[i].Print(false);
}     
delete [] pStrs;   
getchar();

return 0;
}

#if 0


C:\Code\VStudio\VC++9\Silvah\Sil7>Test02
  one ,  two  ,  three,  four ,  five    ,   six
  one   two    three  four   five       six
onetwothreefourfivesix

#endif
#36
Discussion / String::Remove(const TCHAR* pS...
Last post by Frederick J. Harris - June 28, 2017, 06:21:18 PM
String::Remove() is kind of interesting.  This is one that over the years I've gone back and forth on in terms of whether to take the existing object and alter it by removing something or other from it, or maintain the existing object 'as is' and return an altered object in a second string as a return value.  The String Class as I now have it does the later.  Here is an example of that...


// cl Test02.cpp Strings.cpp /O1 /Os /GR- /GS- TCLib.lib kernel32.lib user32.lib
#define UNICODE
#define _UNICODE
#include <windows.h>
#include "stdio.h"
#include "Strings.h"

int main()
{
String s,s1;

s=L"  one ,  two  ,  three,  four ,  five    ,   six";
s.Print(true);
s1=s.Remove(L" ");
s1.Print(true);
getchar();

return 0;
}

#if 0

C:\Code\VStudio\VC++9\Silvah\Sil7>cl Test02.cpp Strings.cpp /O1 /Os /GR- /GS- TCLib.lib kernel32.lib user32.lib
Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Test02.cpp
Strings.cpp
Generating Code...
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Test02.exe
Test02.obj
Strings.obj
TCLib.lib
kernel32.lib
user32.lib

C:\Code\VStudio\VC++9\Silvah\Sil7>Test02
  one ,  two  ,  three,  four ,  five    ,   six
one,two,three,four,five,six

#endif


So the key to getting that to work is to declare a 2nd String to receive the returned String with the spaces removed.
#37
General Discussion / Re: What would be best C++ IDE...
Last post by Ron Allen - June 19, 2017, 05:36:22 PM
Hi,

take a look at Dev C++

http://dev-c.programs.gratis/?lp=bing&tg=us&tp=rs&os=windows&utm_source=bing&utm_medium=cpc&utm_campaign=search

I've used it a little to get my feet wet, it seems ok and the price is right for getting familiar.

Ron
#38
General Discussion / Re: What would be best C++ IDE...
Last post by Andrey Unis - June 18, 2017, 08:12:22 AM
Quote from: Patrice Terrier on June 15, 2017, 02:09:37 PM
Visual Studio, has a built-in debugger, intellisense, and all extra goodies you can expect from a modern compiler.
Visual Studio plus few Extensions:
+ Visual Assist (_https://www.wholetomato.com) => IMHO, must have plugin
+ Tabs Studio (_https://tabsstudio.com)
+ Indent Guides (freeware. Install from Tools -> Extensions and Update)
#39
General Discussion / Re: What would be best C++ IDE...
Last post by Frederick J. Harris - June 16, 2017, 09:24:08 PM
I have the freebee version of VS 2015 installed on my one box but I never hardly use it.  I recall though having to re-install it because the default install didn't install any of the C++ stuff or even the SDK.  That really blew my mind.

So to answer your question, yes, you should be able to use the same Visual Studio IDE for both languages, but if the C++ build system and the SDK isn't installed, you'll be going nowhere fast.

When everything is installed correctly and you go to set up a Project/Solution, the IDE should give you a choice as to what kind of project, i.e., which language, you want to use.  With my Visual Studio 2008 installation I use there's a bunch of choices, e.g., VB.NET, C#.NET, C++ Smart Device, C++, and several others I never use cuz I'm not that familiar with them. 

So you need to check on that.  If the IDE isn't giving you those choices then its my guess you haven't installed those components/languages.   
#40
General Discussion / Re: What would be best C++ IDE...
Last post by Chris Chancellor - June 16, 2017, 04:46:14 PM
Thanxx all

i already have Visual Studio 2015 installed but I'm using VB.NET  , how to use both C++ and vb together?
Can VS 2015 accomodate these 2 languages at once?