I invoke an API and after the answer call my method
func getLikes(result:AnyObject!, response:NSHTTPURLResponse! , error:NSError!){
println(result)
}
And when I try print "result" - I get normal JSON in console, but when I try to convert to String
var t = result as String
have "EXEC_BAD_ACCESS".
I try to do print to targetStream (like NSOutputStream), but I don't find how to do it.
How to convert json to string, any ideas?
Okay, i find solution:
If some tyype you can print, but don't know what it is - object implementation Printable interface(printable)
So, you can do that:
var t:String = result.description
And all, good day
Related
I have the following encoded string in Node;
const test = '\x50\x77\x6b\x6d\x77\x37\x54\x43\x6f\x51\x3d\x3d'
I want to get it's unencoded value Pwkmw7TCoQ==
How can I achieve this?
Use the .toString() method. It should work.
test.toString()
Nothing to do there. Just print the string to the console as it is.
const test = '\x50\x77\x6b\x6d\x77\x37\x54\x43\x6f\x51\x3d\x3d';
console.log(test);
'\x50\x77\x6b\x6d\x77\x37\x54\x43\x6f\x51\x3d\x3d' and 'Pwkmw7TCoQ==' are different notations for the same value.
I got some function:
private fun selectHometown() = File("data/towns.txt")
.readText()
.split("\n")
.shuffled()
.first()
And if I try to get or print some string with the 2 values obtained from this function, the first value disappears. For example:
println("${selectHometown() ${selectHometown() }")
Will only print one city name, while I expect two. I guess the problem is related to string concatenation in Kotlin. Of course, I can get the desired result in a different way, but I'm wondering why this one doesn't work.
Windows way of terminating a line is to use "\r\n" so use it as delimiter :
private fun selectHometown() = File("data/towns.txt")
.readText()
.split("\r\n")
.shuffled()
.first()
println("${selectHometown()} ${selectHometown()}")
I have a ";" delimited string. I need to remove an entry from it. I tried to use slice but that does get sliced string but not the original-modified string.
Here is an example:
var str1: string = 'TY66447;BH31496;PA99001;';
var str2 = str1.slice(16, 23);
console.log(str1);
console.log(str2);
It gives:
TY66447;BH31496;PA99001;
PA99001
But what I want to achieve is TY66447;BH31496;
I am not sure if I am using the correct string method. Please guide how to achieve.
I don't understand what do you want, but it seems that you want:
str1.slice(0, 16);
OK, So I'm having a string and want to split it and return its parts in a string array.
This is my code :
// import std.algorithm;
string include = "one,two,three";
string[] paths = splitter(include,",");
This throws an error : Error: cannot cast from Result to string[]
Even if I try adding a cast(string[]) in front of the function call.
Any ideas?
splitter returns a range which splits lazily.
To split eagerly, use split from std.array.
Alternatively, you can save the range to an array by using std.array.array, like this:
string[] paths = include.splitter(",").array();
Using split() from std.array might be more conventional in this case since it already deals with arrays and you wouldn't need to convert the type or anything, compared to splitter.
Requires:
import std.array;
Usage:
auto paths = split(include, ",");
I have a string ="/show/search/All.aspx?Att=A1". How to get the last value after the 'Att=' in efficient way ?
You could do a split on the '=' character.
Example (in C#):
string line = "/show/search/All.aspx?Att=A1";
string[] parts = line.Split('=');
//parts[1] contains A1;
Hope this helps
If you're only dealing with this one URL then both of the other answers would work fine. I would consider using the HttpUtility.ParseQueryString method and just pull out the item you want by key.
Whatever an
efficient way
is...
Try this:
var str = "/show/search/All.aspx?Att=A1";
var searchString = "Att=";
var answer = str.Substring(str.IndexOf(searchString) + searchString.Length);