Charmed Quark Systems, Ltd. - Support Forums and Community
variable (Local & Global) replace function question - Printable Version

+- Charmed Quark Systems, Ltd. - Support Forums and Community (https://www.charmedquark.com/vb_forums)
+-- Forum: General Discussion (https://www.charmedquark.com/vb_forums/forumdisplay.php?fid=3)
+--- Forum: Installation/Configuration (https://www.charmedquark.com/vb_forums/forumdisplay.php?fid=10)
+--- Thread: variable (Local & Global) replace function question (/showthread.php?tid=5330)



variable (Local & Global) replace function question - znelbok - 02-07-2009

I am playing around with the media repo at the moment and I am in a position where I want to manipulate a local variable.

Currently I need to replace a single character with three characters (space with %20), but the replace command will only replace a single character with a single character.

Is there a way I can change a substring with a different length substring.

Mick


variable (Local & Global) replace function question - Dean Roddey - 02-07-2009

You'll have to do a search, a cut, and an insert probably.


variable (Local & Global) replace function question - znelbok - 02-07-2009

so you mean, split the local variable into multiple local variable based on a desired character as the split point, add a new string at each split point and then append them again?

Can the replace command be modified to allow multiple characters and not just one character?

Mick


variable (Local & Global) replace function question - Dean Roddey - 02-07-2009

I was thinking, find the space, which gives you an index. Do a cut of one character at the index. Then do an insert of %20 at that index.


variable (Local & Global) replace function question - znelbok - 02-07-2009

OK I understand that

How do I loop for a unknown number of spaces. There could be none, there could be five or six?


variable (Local & Global) replace function question - Dean Roddey - 02-07-2009

That you can't do at the action level. I think what you really need is an 'encode URL' that will take a URL and expand it out to the full legal URL form, right? There is support for that at the CML level, but not at the action level yet.


variable (Local & Global) replace function question - znelbok - 02-07-2009

That was just as example

I am trialing sage as well as the http commands for xbmc.

both want different formats so I need to do small manipulations on the string in questions.

Can the replace command for a variable be expanded so that it can replace a single character with multiple characters?

Mick


variable (Local & Global) replace function question - Dean Roddey - 02-07-2009

It could be, or another one provided that does. But it'll be a bit before I can get to it.


variable (Local & Global) replace function question - wuench - 02-08-2009

Here is a method I wrote for the SNMP driver that I think will do what you want. You just need to put it into a macro's start method.

Code:
//-------------- ReplaceSubStr -------------------------------------------
// Replaces the substring strSought with strReplace in strSearched.  Not
// case sensitive, and will do multiple replacements.
//
//-----------------------------------------------------------------------
Method ReplaceSubStr ([InOut] String strSearched,
                    [In] String strSought,
                    [In] String strReplace) Returns Boolean
    Begin
    Locals=
        String strWork;
        String strBefore;
        String strAfter;
        Card4  c4Pos;
        Card4  c4Len;
        Card4  c4WorkLen;
        Card4  c4AfterPos;
        Boolean bRetVal;
    EndLocals;

    strWork := strSearched;
    c4Len := strSought.GetLength();
    bRetVal := False;
    
    While (strWork.FindSubStr(strSought, c4Pos, False))
        // Init Variables
        bRetVal := True;
        strBefore := "";
        strAfter := "";

        // Get Before String
        If (c4Pos > 0)
            strWork.ExtractSubStr(0, c4Pos, strBefore);
        EndIf;

        // Get After String
        c4AfterPos := c4Pos+c4Len;
        c4WorkLen := strWork.GetLength();
        If (c4AfterPos < c4WorkLen)
            strWork.ExtractSubStr(c4AfterPos, Card4.kMaxValue, strAfter);
        EndIf;

        // Do Replacement
        strWork := strBefore + strReplace + strAfter;
    EndWhile;
    
    strSearched := strWork;
    Return bRetVal;
EndMethod;