-3

I want to trim a string that looks like this 1:"Transmitters" and i want it to look like this = Transmitters.

3
  • 2
    K, sooo...what's stopping you from doing that?
    – ElGavilan
    Jan 7, 2015 at 13:15
  • var str = @"1:""Transmitters""".Substring(3, 12); Jan 7, 2015 at 13:15
  • Form the variations of answers you are getting it seems it's unclear if the literal "this" is part of the input and output. You should format your question to clarify.
    – Filburt
    Jan 7, 2015 at 13:23

5 Answers 5

1

You can split the string with ':' and remove the quotes.

var str = "1:""Transmitters""";
var output = str.Split(':')[1].Replace("""","");

or you can also use Regular Expressions (Regex class).

1

To extract between quotes

int pos = str.IndexOf('"');
str = str.Substring(pos + 1, str.Length - pos - 2);
2
  • But if any character appears after second quote...
    – Renatas M.
    Jan 7, 2015 at 13:27
  • Then str = str.Substring(pos + 1, str.IndexOf('"', pos + 1) - pos - 1);
    – Alex K.
    Jan 7, 2015 at 13:33
0

I take the title literally:

str = str.Trim('1',':','"');
0

If the chracters that you want to remove always has the same size, you can just use the Substring method:

string s = "1:\"Transmitters\"";
s = s.Substring(3, s.Length - 4);

If the number before the colon can change, look up the psoition of the colon in the string:

string s = "123:\"Transmitters\"";
int pos = s.IndexOf(':');
s = s.Substring(pos + 2, s.Length - pos - 3);
0

How about this?

string temp = "1:\"Transmitters\"";
temp = temp.Replace("\"", string.Empty).Split(':')[1];

Not the answer you're looking for? Browse other questions tagged or ask your own question.