Reading and trying things for yourself is going to be more effective than wishing.
If you want to be able to use more advanced features, you're going to need to understand them in order to be able to combine them into something that does what you're looking for.
For now, try this command:
Set text [~textFile] to [C:\text.txt]
Set text [~startingOffsetSearchTerm] to 'Welcome to'
Set text [~searchMode] to 'StartsWith'
Set integer [~targetLine] value to 1
Set integer [~targetSection] value to -1
Inline C# Function: Get a line and optionally a section of that line, with optional offset based on the contents of a line, wait until execution finishes
Write [Blue] '"{TXT:~splitOutput}"' to log
where "Get a line and optionally a section of that line, with optional offset based on the contents of a line" contains
using System;
public class VAInline
{
enum SearchMode
{
Contains,
StartsWith,
EndsWith
}
public void main()
{
string input = VA.GetText("~textFile");
if (input == null)
{
VA.WriteToLog("Cannot get line, no file set", "red");
return;
}
int targetLine = VA.GetInt("~targetLine") ?? -1;
if (targetLine < 1)
{
VA.WriteToLog("Cannot get line, no or invalid line number set", "red");
return;
}
int targetSection = VA.GetInt("~targetSection") ?? -1;
string[] lines = input.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
string startingOffsetSearchTerm = VA.GetText("~startingOffsetSearchTerm");
if (!String.IsNullOrEmpty(startingOffsetSearchTerm))
{
string chosenSearchMode = VA.GetText("~searchMode") ?? "";
SearchMode currentSearchMode = SearchMode.Contains;
if (chosenSearchMode.Equals("StartsWith", StringComparison.OrdinalIgnoreCase))
{
currentSearchMode = SearchMode.StartsWith;
}
else if (chosenSearchMode.Equals("EndsWith", StringComparison.OrdinalIgnoreCase))
{
currentSearchMode = SearchMode.EndsWith;
}
bool searchTermFound = false;
for (int i = 0; i < lines.Length; i++)
{
if (currentSearchMode == SearchMode.StartsWith)
{
if (lines[i].StartsWith(startingOffsetSearchTerm, StringComparison.OrdinalIgnoreCase))
{
searchTermFound = true;
targetLine += i;
break;
}
}
else if (currentSearchMode == SearchMode.EndsWith)
{
if (lines[i].EndsWith(startingOffsetSearchTerm, StringComparison.OrdinalIgnoreCase))
{
searchTermFound = true;
targetLine += i;
break;
}
}
else
{
if (lines[i].IndexOf(startingOffsetSearchTerm, StringComparison.OrdinalIgnoreCase) > -1)
{
searchTermFound = true;
targetLine += i;
break;
}
}
}
if (!searchTermFound)
{
VA.WriteToLog("Search term \"" + startingOffsetSearchTerm + "\" was not found within the file using search mode \"" + chosenSearchMode + "\"; Could not get line", "red");
return;
}
}
if (targetLine > lines.Length)
{
VA.WriteToLog("Warning: Target line is " + targetLine + ", but the file only contains " + lines.Length + " lines", "orange");
return;
}
if (targetSection < 0)//If no section has been specified, return the whole line
{
VA.SetText("~splitOutput", lines[targetLine - 1]);
}
else
{
string[] sections = lines[targetLine - 1].Split(' ');
if (targetSection > sections.Length - 1)
{
VA.WriteToLog("Warning: Target section is " + targetSection + ", but the line only contains " + sections.Length + " sections", "orange");
return;
}
VA.SetText("~splitOutput", sections[targetSection]);
}
}
}
This is again a hybrid of all the preceding functionality, and the new one.
The "~textFile" and "~targetLine" variables are mandatory, I.E. they must have a valid value in order for the inline function to work.
Optional variables are:
"~startingOffsetSearchTerm", which specifies text to search for, so that if that text is found, that line will effectively become line 1 for the purposes of retrieving text (which also means "~targetLine" is relative to that, I.E. setting that to 1 will get the contents of the found line, settings it to 2 will get the contents of the line after the found line, etc...)
"~searchMode", which specifies where within a line the text provided in "~startingOffsetSearchTerm" should be located. Valid values are "StartsWith", "EndsWith", and "Contains", though the latter is the default search mode if nothing (or an invalid value) is specified in "~searchMode".
"~targetSection", which works as it did before (set to -1 in the example, which has the same effect as not setting it at all, I.E. returning the entire line).
Both "~startingOffsetSearchTerm" and "~searchMode" are case-insensitive, E.G. "welcome to" in the former would still allow "Welcome to" to be found, and "startswith" would have the same effect as "StartsWith" in the latter.
If the text specified in "~startingOffsetSearchTerm" cannot be found using the specified search mode, the output variable will not be set.
If you require additional functionality, you'll want to look into C# and string manipulation.
Note that if you need the remainder of the line starting with "Welcome to", but don't want to split it up into individual sections, you could use the "{TXTSUBSTR:}" token on the output with the starting value set to 11, and the length left blank, which will skip the 11 characters (including the space) at the start of the line (it gets the text starting at position 11, which, because as mentioned before most things use zero-indexing, means the twelfth character).
E.G.
Write [Blue] '"{TXTSUBSTR:~splitOutput:11:}"' to log