Skip to main content
Solved

Does NetBrain Support Finding the Character Position in a String Variable

  • May 12, 2026
  • 2 replies
  • 32 views

Forum|alt.badge.img

I’m learning NetBrain.

I recently learned how to use a variable method to perform a substring operation on a variable, ex. $Stringvar1.Substring(0,2)

After discoverying that that operator worked, I tried to use a “length” method to obtain the number of characters in a string variable. Again an example is: $Stringvar1.length

This also worked.

The next thing I want to find is a function that searches a string variable for a character or substring and returns the starting postition.

The Python string methods for “find” or “index” don’t seem to function.

The NetBrain function “find” doesn’t return the search pattern in the target string only a boolean value.

Is there a function or method that will return the numerical position of character pattern in a string variable?

Best answer by prallu

Hey ​@dsatbae ,

 

Python string methods like find() and index() won't work here — NetBrain's variable expressions evaluate as C#, not Python. That's also why Substring() and .Length worked for you: those are C# string methods.

So, You can use a single-line C# expression anywhere NetBrain's built-in functions fall short.

Just like Substring(0,2) is a C# string method (not a NetBrain function), you can use other C# string methods the same way. For finding the position of a character or substring, use IndexOf():

$Stringvar1.IndexOf("abc")

This returns the zero-based starting index of the first occurrence of "abc" in the string, or -1 if it's not found.

A few useful variants:

  • $Stringvar1.IndexOf("abc", 5) — start searching from index 5
  • $Stringvar1.LastIndexOf("abc") — get the position of the last occurrence
  • $Stringvar1.IndexOf('x') — single character (note single quotes for char)

 

General tip: Whenever a built-in NetBrain function doesn't exist for what you need to do on a string (or number, or list), remember that you can fall back to a single-line C# expression on the variable directly. Most standard C# string methods (Substring, Length, IndexOf, Replace, Split, ToUpper, ToLower, Trim, Contains, StartsWith, EndsWith, etc.) work this way.

If you're searching for "how do I do X on a string in NetBrain,", when there is no built-in function, try searching for the C# equivalent instead of the Python one

2 replies

prallu
  • Frequent Participant
  • Answer
  • May 13, 2026

Hey ​@dsatbae ,

 

Python string methods like find() and index() won't work here — NetBrain's variable expressions evaluate as C#, not Python. That's also why Substring() and .Length worked for you: those are C# string methods.

So, You can use a single-line C# expression anywhere NetBrain's built-in functions fall short.

Just like Substring(0,2) is a C# string method (not a NetBrain function), you can use other C# string methods the same way. For finding the position of a character or substring, use IndexOf():

$Stringvar1.IndexOf("abc")

This returns the zero-based starting index of the first occurrence of "abc" in the string, or -1 if it's not found.

A few useful variants:

  • $Stringvar1.IndexOf("abc", 5) — start searching from index 5
  • $Stringvar1.LastIndexOf("abc") — get the position of the last occurrence
  • $Stringvar1.IndexOf('x') — single character (note single quotes for char)

 

General tip: Whenever a built-in NetBrain function doesn't exist for what you need to do on a string (or number, or list), remember that you can fall back to a single-line C# expression on the variable directly. Most standard C# string methods (Substring, Length, IndexOf, Replace, Split, ToUpper, ToLower, Trim, Contains, StartsWith, EndsWith, etc.) work this way.

If you're searching for "how do I do X on a string in NetBrain,", when there is no built-in function, try searching for the C# equivalent instead of the Python one


Forum|alt.badge.img
  • Author
  • New Participant
  • May 13, 2026

pallu,

Thank you for that informaton.

This will allow me to solve any future issues with text maniplation.

(I also get another programming language to learn:))