Elfoc
Elfoc

Reputation: 3689

Parse text from textbox

i have string in textbox:

  `New-Value = 12,34   -- Old-Values: 12,31,`

what i'd like to do is to get Old-Value so "12,31,"

How can i get from this textbox this specific information do this? So value is between ":" and ","

Tnx

Upvotes: 0

Views: 1649

Answers (3)

pamidur
pamidur

Reputation: 612

const string oldPointer = "Old-Values: ";
var text = "New-Value = 12,34   -- Old-Values: 12,31,";
var old = text.Substring(text.IndexOf(oldPointer) + oldPointer.Length).TrimEnd(',');

Upvotes: 0

Tigran
Tigran

Reputation: 62265

Not very clear if this is a fixed (static) format of your string, but by the way:

A simple solution could be:

string str = "New-Value = 12,34   -- Old-Values: 12,31,"; 
str.Substring(str.IndexOf(':') + 1);

More complex one should involve Regular expressions, like an answer of L.B or others if any.

Upvotes: 0

L.B
L.B

Reputation: 116178

Regex.Match("New-Value = 12,34 -- Old-Values: 12,31,",@"\:(.+)\,").Groups[1].Value.Trim()

Upvotes: 2

Related Questions