Hello Ventuzians!
THE FORUMS ARE CLOSED!
Please join our discord server HERE!! << click me
We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server
Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!
THE FORUMS ARE CLOSED!
Please join our discord server HERE!! << click me
We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server
Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!
Search Replace Array
Moderator: Support
Search Replace Array
Hey guys..
Was wondering if there is a way to use Search and replace node inputting Search Array and Replace Array?
For example:
Input: 2018 - 10 - 13
Search: 0,1,2,3,4,5,6,7,8,9,10,11,12,13
Replace: a,b,c,d,e,f,g,h,i,j,k,l,m,n
Output = cabi - k - n
or Something similar to that?
Was wondering if there is a way to use Search and replace node inputting Search Array and Replace Array?
For example:
Input: 2018 - 10 - 13
Search: 0,1,2,3,4,5,6,7,8,9,10,11,12,13
Replace: a,b,c,d,e,f,g,h,i,j,k,l,m,n
Output = cabi - k - n
or Something similar to that?
-
- Posts: 666
- Joined: 18 Jan 2012, 20:56
- Location: wuppertal
- Contact:
Re: Search Replace Array
If so, than just by a script...
But i think, that even with a script it is maybe complex, because 2018 should be replace letter by letter but 10 should be replaced in total...
But i think, that even with a script it is maybe complex, because 2018 should be replace letter by letter but 10 should be replaced in total...
Re: Search Replace Array
you can do this in a string expression. See attached vza. Of course if the string is very large or the number of replacements is very high, at some point this might have an impact on the performance.
Code: Select all
{
string res = A;
if( !(string.IsNullOrWhiteSpace(B) || string.IsNullOrWhiteSpace(C)) )
{
var a = B.Split(',');
var b = C.Split(',');
int max = Math.Max(a.Length, b.Length);
for(int i = 0; i < max; ++i)
{
res = res.Replace(a[i], b[i]);
}
}
return res;
}
- Attachments
-
- replace_chars_001.vza
- (6.88 KiB) Downloaded 175 times
-
- Posts: 666
- Joined: 18 Jan 2012, 20:56
- Location: wuppertal
- Contact:
Re: Search Replace Array
Hi rou,
nice example but... as i thought, it doesn't work the way he likes
2018-10-13 should be cabi-k-n but in your example it is cabi-ba-bd
For eg. the 10 is replaced by ba... what is correct for me because first you check for 0 what has a replacement... then for 1 what have a replacement and than, there is no more 10 existing ... but he like to replace it by k!
So you need to make sure, that the search AND replace string is in the right order.
If you change it to:
Search: 10,11,12,13,0,1,2,3,4,5,6,7,8,9
Replace: k,l,m,n,a,b,c,d,e,f,g,h,i,j
It could work
Greetings
Christian
nice example but... as i thought, it doesn't work the way he likes
2018-10-13 should be cabi-k-n but in your example it is cabi-ba-bd
For eg. the 10 is replaced by ba... what is correct for me because first you check for 0 what has a replacement... then for 1 what have a replacement and than, there is no more 10 existing ... but he like to replace it by k!
So you need to make sure, that the search AND replace string is in the right order.
If you change it to:
Search: 10,11,12,13,0,1,2,3,4,5,6,7,8,9
Replace: k,l,m,n,a,b,c,d,e,f,g,h,i,j
It could work
Greetings
Christian
-
- Posts: 666
- Joined: 18 Jan 2012, 20:56
- Location: wuppertal
- Contact:
Re: Search Replace Array
Hi Rou...
By the way: didn't knew, that it works with a single Expression
Thank you!!
And i have tested the other order in the strings... works
By the way: didn't knew, that it works with a single Expression
Thank you!!
And i have tested the other order in the strings... works
Re: Search Replace Array
okok. Here we go again:
Code: Select all
string res = inText;
if(!( string.IsNullOrWhiteSpace(inText) || string.IsNullOrWhiteSpace(inSearch) || string.IsNullOrWhiteSpace(inReplace) ) )
{
var a = inSearch.Split(',');
var b = inReplace.Split(',');
if( a.Length == b.Length )
{
var pairs = new List<Tuple<string,string>>();
for(int i = 0; i < a.Length; ++i)
{
pairs.Add( new Tuple<string,string>(a[i], b[i]));
}
pairs.Sort((left, right) => -left.Item1.Length.CompareTo(right.Item1.Length) );
foreach(var pair in pairs)
{
res = res.Replace(pair.Item1, pair.Item2);
}
}
}
outText = res;
- Attachments
-
- replace_chars_002.vza
- (9.01 KiB) Downloaded 179 times
Re: Search Replace Array
Queue?In the future A control should be added
Re: Search Replace Array
This is great guys
Leru, exactly what I needed Thanks a lot!
Leru, exactly what I needed Thanks a lot!
Re: Search Replace Array
Nice solution.
Here is a solution with simple ventuz nodes without scripting.
Because you can handle the numbers as a indexer for the letters array you not really need a replacement, that`s my thought.
The input is a date YYYY - MM - DD format, i only have to split the year number in its parts. The month and day numbers can be used as they are. The input is a property at the container - ConvertToLetters
Here is a solution with simple ventuz nodes without scripting.
Because you can handle the numbers as a indexer for the letters array you not really need a replacement, that`s my thought.
The input is a date YYYY - MM - DD format, i only have to split the year number in its parts. The month and day numbers can be used as they are. The input is a property at the container - ConvertToLetters
3DJo - [Ventuz] freelancer and trainer