I know there is a search / replace for variables.
But when it comes to lists, is it possible to search each line and replace a word?
Example data
List name: A
Sample data a
Sample data b
Sample data c
To create a custom code so that when there is "a", it changes to x1
I checked a few existing snippets posted in the forum. This one below is the most close, but it will remove that whole line and replace it with x1. My goal is only to replace a particular word.
If there can be an option to define multiple matches, that would be great.
a > x1
b > x2
c > x3
The code I found that does search and replace, however it remove the whole line that contains this particular match:
The code below will remove whole line that contains a number, and replace it with 1
I found the code in this forum.
But when it comes to lists, is it possible to search each line and replace a word?
Example data
List name: A
Sample data a
Sample data b
Sample data c
To create a custom code so that when there is "a", it changes to x1
I checked a few existing snippets posted in the forum. This one below is the most close, but it will remove that whole line and replace it with x1. My goal is only to replace a particular word.
If there can be an option to define multiple matches, that would be great.
a > x1
b > x2
c > x3
The code I found that does search and replace, however it remove the whole line that contains this particular match:
The code below will remove whole line that contains a number, and replace it with 1
I found the code in this forum.
C#:
var sourceList = project.Lists["A"];
var parserRegex = new Regex("\\d{1,2}"); // Вот регулярка на поиск чисел
lock(SyncObjects.ListSyncer)
{
for(int i=0; i < sourceList.Count; i++) // Пробегаемся по списку
{
if (parserRegex.IsMatch(sourceList[i])) // Если регулярка срабатывает, то..
{
sourceList[i]="1"; // Заменяем текущий элемент на цифру 1
}
}
}