Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
variable (Local & Global) replace function question
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.

You'll have to do a search, a cut, and an insert probably.
Dean Roddey
Explorans limites defectum
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?

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.
Dean Roddey
Explorans limites defectum
OK I understand that

How do I loop for a unknown number of spaces. There could be none, there could be five or six?
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.
Dean Roddey
Explorans limites defectum
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?

It could be, or another one provided that does. But it'll be a bit before I can get to it.
Dean Roddey
Explorans limites defectum
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.

//-------------- 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
        String strWork;
        String strBefore;
        String strAfter;
        Card4  c4Pos;
        Card4  c4Len;
        Card4  c4WorkLen;
        Card4  c4AfterPos;
        Boolean bRetVal;

    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);

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

        // Do Replacement
        strWork := strBefore + strReplace + strAfter;
    strSearched := strWork;
    Return bRetVal;
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]

Possibly Related Threads…
Thread Author Replies Views Last Post
  Global Cache GC-100 - How to add IR Code??? Deane Johnson 7 3,156 11-25-2019, 09:26 AM
Last Post: Deane Johnson
  Server hardware question rhosch 3 2,493 10-02-2019, 11:19 AM
Last Post: rhosch
  Basic Z Wave/CQC Integration Question MikeW 6 4,278 12-05-2018, 01:12 PM
Last Post: MikeW
  Time to replace my mSata HDD. ellisr63 4 2,305 11-23-2018, 11:47 AM
Last Post: ellisr63
  event and subsequent countdown timer question dogman 9 5,605 05-03-2018, 06:36 PM
Last Post: dogman
  webriva template question lleo 21 12,324 01-08-2018, 08:53 AM
Last Post: Dean Roddey
  global actions and lighting groups jkmonroe 11 8,029 06-02-2017, 08:27 PM
Last Post: Dean Roddey
  How to pass a variable into a field moniker EST 3 2,876 08-30-2016, 11:01 AM
Last Post: EST
  Tivo control question MikeA 21 13,229 12-26-2015, 06:29 PM
Last Post: dogman
  Question on Hue and Lux driver Deane Johnson 5 3,516 05-21-2015, 01:39 PM
Last Post: Deane Johnson

Forum Jump:

Users browsing this thread: 1 Guest(s)