Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



 1633

How to write this line of code?

by Nalon - 16 February, 2020 - 04:09 PM
This post is by a banned member (Nalon) - Unhide
Nalon  
Infinity
131
Posts
27
Threads
5 Years of service
#1
Hi, I'm making a discord bot right now but I have ran into an issue I can't seem to fix...  Pepi

I need to change the text of my richtextbox2 to : {"username":"test","discriminator":9999}
The issue is the " is making errors because C# thinks I am ending the string there. I can't use ' because it says there are too many characters in a character literal.

So the code looks like this:
Code:
richtextbox2.Text = "{"username":"test","discriminator":9999}"

But yeah, the issue is it thinks I am ending the string. I also cannot use ' ,  it has to be speech marks not apostrophes. 

Is there some other character I can use or a line of code or something so it just takes that as the string? For instance: 

richtextbox2.Text = ${"username":"test","discriminator":9999}$ 

So I use the dollar symbol as the speech marks so it doesn't interfere...
DISCORD SERVER : CLICK
This post is by a banned member (Gaztoof) - Unhide
Gaztoof  
Infinity
1.456
Posts
1.113
Threads
5 Years of service
#2
richtextbox2.Text = "{\"username\":\"test\",\"discriminator\":9999}\"
LONG LIVE CYBERNIGGERS
"[/size][/color][/b][/u]@Gaztoof has decided to neg me because I've told him to not send too many messages per second in the SB as that annoys many. He then accused me of being Indian, for no legitimate reason"
[u][b][color=#f1c40f][size=xx-large][Image: vlr6kzb.gif]
[Image: floyd-george-e1590967609961.jpg]
[Image: kOX40Je.png]

my signature is epic, nothing to add 
https://i.imgur.com/13lycpV.gif consider this an image tysm
This post is by a banned member (Nalon) - Unhide
Nalon  
Infinity
131
Posts
27
Threads
5 Years of service
#3
(16 February, 2020 - 04:14 PM)Gaztoof Wrote: Show More
richtextbox2.Text = "{\"username\":\"test\",\"discriminator\":9999}\"

I got it now, thankssssss
DISCORD SERVER : CLICK
This post is by a banned member (Suspect) - Unhide
Suspect  
Registered
75
Posts
2
Threads
4 Years of service
#4
(This post was last modified: 02 April, 2020 - 05:20 PM by Suspect.)
Easier way would be:

JObject jobject = new JObject();
jobject.Add("username", "test");
jobject.Add("discriminator", "9999");

richtextbox2.Text = jobject.ToString();

Newtonsoft.Json Package is required.

 

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)