Posts: 4,225
Threads: 365
Joined: May 2005
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
Posts: 40,483
Threads: 491
Joined: Aug 2002
You'll have to do a search, a cut, and an insert probably.
Dean Roddey
Explorans limites defectum
Posts: 4,225
Threads: 365
Joined: May 2005
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
Posts: 40,483
Threads: 491
Joined: Aug 2002
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
Posts: 4,225
Threads: 365
Joined: May 2005
OK I understand that
How do I loop for a unknown number of spaces. There could be none, there could be five or six?
Posts: 40,483
Threads: 491
Joined: Aug 2002
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
Posts: 4,225
Threads: 365
Joined: May 2005
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
Posts: 40,483
Threads: 491
Joined: Aug 2002
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
Posts: 3,415
Threads: 158
Joined: Jan 2006
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;