Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
variable (Local & Global) replace function question
#1
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
Reply
#2
You'll have to do a search, a cut, and an insert probably.
Dean Roddey
Explorans limites defectum
Reply
#3
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
Reply
#4
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
Reply
#5
OK I understand that

How do I loop for a unknown number of spaces. There could be none, there could be five or six?
Reply
#6
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
Reply
#7
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
Reply
#8
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
Reply
#9
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;
Wuench
My Home Theater/Automation Website

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


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

Forum Jump:


Users browsing this thread: 1 Guest(s)