How to convert data in unityscript - unity3d

Now I have data like this "1234567890", first it is System.Object
I want convert it to long.
I tried like this
(long) data
data as long
data as System.Int64
It seems they all not work,anyone can help me?

First got your object as string if needed:
string mystringnumber = mysystemobject as String;
You can use this:
long.parse(mystringnumber);
or:
if (long.TryParse(mystringnumber,null))
{
dosomething();
}

Related

ObjectScript Library.FileBinaryStream convert into a string

How can I create a string a from binary stream? I tried StreamGet and OutputToDevice class methods but that is not returning the string. Is there another class I should use
Thanks :)
Assuming that stream is a %Library.FileBinaryStream:
set string = stream.Read($$$MaxStringLength)
Note that string can't be more than 7mb, while stream can be bigger.

Javers:Ignore specific fields in Value Object while comparing two jsons

I am trying to compare two jsons, expected and the API Response using Javers, as part of testing. I want the comparison to exclude the ID parameters that are dynamically generated by response.
My VO is like
public class expectedResponse{
#DiffIgnore
private String id;
private String name;
}
Both my expectedResponse- which is read from excel file and the actual response from API are deserialized into this format and then both the responses are compared.
JsonNode expectedOutput = mapper.readTree(expected.toString());
JsonNode apiResponse = mapper.readTree(actual.toString());
diff=javers.compare(expectedOutput, apiResponse);
But this comparison doesn't exclude/ignore the ID field. Any Idea how I can get it to work? I want only the ID field excluded in comparison results, diff in name should be listed.
Also question 2> I am trying to list the changes from diff
if (diff.hasChanges())
{
List<ValueChange> changes=diff.getChangesByType(ValueChange.class);
for (ValueChange change : changes)
{
logger.info(change.getPropertyName()+ "||" +change.getLeft().toString() + "||" +change.getRight().toString());
change.getPropertyName()- doesnt print the property's name but simply prints "_value" as its value.
Can you pls help in identifying what is going wrong with the code and how can I get this fixed? I am not finding much useful documentations about Javers anywhere in google. Any help is appreciated.
You should compare you domain object instead of object with JsonNode class, look that #DiffIgnore annotation is present only in your domain class and there is no connection between JsonNode and ExpectedResponse, thats why Javers doesn't know to ignore this field.
To summarise, your code should looks like this:
ExpectedResponse expectedOutput = ...
ExpectedResponse apiResponse = ...
diff=javers.compare(expectedOutput, apiResponse);

NTriplesParser extract textual value from string

I am using dotnetrdf and trying to parse some triples with NTriplesParser. I have my own handler RobHandler in which I process each triple in turn.
public class RobHandler : BaseRdfHandler
{
protected override bool HandleTripleInternal(Triple t)
{
string predicateUrl = ((BaseUriNode)(t.Predicate)).Uri.AbsoluteUri;
string value = t.Object.ToString();
}
}
This works fine but I want to get the object minus the language. My objects look like "Lincoln"#en. I could obviously write some code to remove the #en bit, but I'd rather use some library code rather than my own that hard-coded strings like #en. To do this I think I need to create a LiteralNode but there doesn't seem to be a way to get from a string which is what I have (my variable value) to a LiteralNode.
How can I extract just the textual value from an object string?
Actually I think I have the answer myself:
if (t.Object.NodeType == NodeType.Literal)
{
var node = (ILiteralNode)t.Object;
}

Can a composite format in String.Format() be used to return a substring?

I apologize for what seems to be an exceedingly simple question, but after 4 hours of searching and beating my head against the wall, I'm doubting my sanity.
I need a string format expression that trims a supplied string argument much like Substring(0,1). Although I've never seen this in code, it just seems like it should be possible.
Here's a very basic example of what I'm trying to do:
string ClassCode = "B608H2014"; // sample value from the user's class schedule
string fRoom = "{0:0,2}";
string fGrade = "{0:2,2}";
string fYear = "{0:5,4}";
string Classroom = String.Format(fRoom, ClassCode); // intended result - "B6"
string Gradelevel = String.Format(fGrade, ClassCode); // intended result - "08"
string Schoolyear = String.Format(fYear, ClassCode); // intended result - "2014"
This is a very basic example, but I'm trying to use the String.Format() so I can store the format pattern(s) in the database for each respective DTO property since the class code layouts are not consistent. I can just pass in the formats from the database along with the required properties and it extracts what I need.
Does this make sense?

How can I get specific values out of a JsonFX deserialized object?

I'm using JsonFX (it's a requirement, Json.Net isn't an option) to pull values out of Json, but I don't want to have to create a class to deserialize to for every bit of Json that I want to parse. So if I have this bit of JSON:
{
Parent:
{
Name: "John",
Child:
{
Name: "Bob",
Age: 20
}
}
}
I'd like to randomly access Child.Name. With Json.Net, I'd just do JObject.Parse(json)["Parent"]["Child"]["Name"]. I need to do the same, using JsonFX.
Using the debugger, I can see that this:
Object results = JsonFx.Json.JsonReader.Deserialize(response);
Pretty much gets me there. If I look at results, it's essentially a dictionary, with all of the data in a format that I would expect. The problem is, because it's an Object, I can't access any of those values. results["Parent"] doesn't compile.
How can I get at these values, without creating a class that mirrors the data?
JsonFX is awesome. Just read it into a dynamic and access the data.
dynamic j = new JsonFx.Json.JsonReader().Read( response );
string ParentName = j.Parent.Name;
string ChildName = j.Parent.Child.Name;
// ...