7 Replies - 221 Views - Last Post: 25 January 2019 - 09:39 AM

#1 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Easiest Way to Remove Double Quotes " " from a String^ ?

Posted 24 January 2019 - 01:14 PM

I didn't think this would be so difficult, but I'm trying to remove double quotes " "s from the start and end of managed String^ and not having luck with these methods:

String^ _trimmed = driverNameTextBox->Text->TrimStart('"\""');
	
String^ _trimmed = driverNameTextBox->Text->TrimStart('""');

String^ _trimmed = driverNameTextBox->Text->TrimStart('\""');

String^ _trimmed = driverNameTextBox->Text->TrimStart('""');

String^ _trimmed = _trimmed->Replace('"\""', '""');

String^ _trimmed = _trimmed->Replace('\"', '""');

String^ _trimmed = _trimmed->Replace('"', '""');



I'm not getting any exceptions but the " char is not removed. What am I doing wrong? :taz:/>/>

I also tried this, no dice

_trimmed->Replace("\"", ""); 


This post has been edited by hexagod: 24 January 2019 - 01:20 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Easiest Way to Remove Double Quotes " " from a String^ ?

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15111
  • View blog
  • Posts: 60,452
  • Joined: 12-June 08

Re: Easiest Way to Remove Double Quotes " " from a String^ ?

Posted 24 January 2019 - 01:37 PM

Do you have a text example?

Ex:
	String^ foo = "\"this is a test\"";

	String^ _trimmed = foo->Replace("\"", "");


	Console::WriteLine(foo);
	Console::WriteLine(_trimmed);



"this is a test"
this is a test

Was This Post Helpful? 1
  • +
  • -

#3 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: Easiest Way to Remove Double Quotes " " from a String^ ?

Posted 24 January 2019 - 01:50 PM

Sure,
so let's say that I do:

	String^ _trimmed = driverNameTextBox->Text;
	
	_trimmed->Replace("\"", "");

	textBox4->Text = _trimmed;



and that code is inside a TextChanged event listener then I paste this String^ into the textBox

"Microsoft Print To PDF" ...

the quotes are not removed when that String^ passes into textBox4 ... I've tried all of the methods above and then some!
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15111
  • View blog
  • Posts: 60,452
  • Joined: 12-June 08

Re: Easiest Way to Remove Double Quotes " " from a String^ ?

Posted 24 January 2019 - 01:55 PM

What is printed out after '3_trimmed->Replace("\"", "");'?
Was This Post Helpful? 0
  • +
  • -

#5 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: Easiest Way to Remove Double Quotes " " from a String^ ?

Posted 24 January 2019 - 02:07 PM

Exactly what was input, basically what I'm trying to do is remove quotes because PowerShell outputs CSV files with ""s around all the fields. The TextFieldParser works really well and automatically removes them in C# but I don't think it's possible to use it in Managed C++ without more work than it's worth.

for your question, if I paste:

"Microsoft XPS Document Writer"

"Microsoft Print to PDF"

into the driverNameTextBox, what comes out in textBox4 is:

"Microsoft XPS Document Writer"

"Microsoft Print to PDF"
Was This Post Helpful? 0
  • +
  • -

#6 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: Easiest Way to Remove Double Quotes " " from a String^ ?

Posted 24 January 2019 - 02:54 PM

I can't believe I did this... forgot to add _trimmed =

derp

	_trimmed = driverNameTextBox->Text->Replace("\"", "");

	textBox4->Text = _trimmed;


Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6968
  • View blog
  • Posts: 23,678
  • Joined: 05-May 12

Re: Easiest Way to Remove Double Quotes " " from a String^ ?

Posted 24 January 2019 - 08:38 PM

Using Replace() will also replace quotes that are inside the string, instead of just the quotes at the beginning and end of the string. What's wrong with simply using Trim()?

Attached Image
Was This Post Helpful? 0
  • +
  • -

#8 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: Easiest Way to Remove Double Quotes " " from a String^ ?

Posted 25 January 2019 - 09:39 AM

Well in this case it's no big deal because I'm parsing printer names and drivers that don't allow " character. But yes, that would be another way to do it.

Frankly I'd rather have this thread deleted because it's embarrassing lol. Sorry, I have really hectic schedule so a lot of times I miss little mistakes I've made. The problem was that I wasn't assigning the return value.

It was a major derpity derp derp on my part :sweatdrop:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1