How to fetch a particular part of a string from the same string in Swift? [closed] - swift

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to fetch a part of string from a string. E.g. I have a string say sampleStringUrl which holds "http://some.something.net/update/user". So, I want to get only "some.something.net" from sampleStringUrl.

Like that you want to get Host URL.
var urlString = "https://stackoverflow.com/questions/6162522/get-the-domain-part-of-an-url-string"
var url = URL(string: urlString)
var domain = url?.host
print(domain!) //stackoverflow.com

Related

Convert array into comma separated value of String [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have an array and I want to convert it into String but separated each element by '","
List<String> list = ["India","China","USA"];
var string = list.join(',');
print(string); //output = "India,China,USA"

How do I sort an array of an array in Swift 5 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
For example I have
[
["A",1]
["B",5]
["C",3]
]
How do i sort it so that it returns in Highest to lowest value B, C, A
You can do in following way:
a.sort {
return $0.last as! Int > $1.last as! Int
}
Don't forget to add additional checks while using this code, case where the last item is not an integer or there is an array not in the expected format. Otherwise, it will lead to a crash.

What possible values are JsonOptions in GlueContext#getSinkWithFormat [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Look at this:
glueContext.getSinkWithFormat(connectionType = "s3",
options = JsonOptions(
Map("path" -> outputLgSingleDir,
"partitionKeys" -> List("org_name"))),
format = "parquet", transformationContext = "")
.writeDynamicFrame(lHistory)
What possible values for JsonOptions are?

How to search for a duplicate in a given string using scriptlet? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
How can I search for a duplicate in a given string using a scriptlet?
ScripletInput= a,b,c,a
Here the letter 'a' is repeating. If it is repeating more than once, then it should exit, else it can go ahead.
Please see Remove occurrences of duplicate words in a string
The code below will remove duplicates in a string.
<script type="text/javascript">
str=prompt("Enter String::","");
arr=new Array();
arr=str.split(",");
unique=new Array();
for(i=0;i<arr.length;i++)
{
if((i==arr.indexOf(arr[i]))||(arr.indexOf(arr[i])==arr.lastIndexOf(arr[i])))
unique.push(arr[i]);
}
unique.join(",");
alert(unique);
</script>

Getting weirdly formatted NSDictionary value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
var nsarray:[NSMutableDictionary] = [["object":["uid":["age":"26","gender":"male"]]]]
print(nsarray[0]["object"])
That is how it looks. I want to get the value "uid", so when it prints it is just "uid". Currently it is printing:
"uid":["age":"26","gender":"male"]
I want to get the "uid" value. Meaning when it prints it is just "uid". "uid" is a placeholder for a unique ID so I won't know what the uid is.
It looks like "object" key contains another dictionary, which has exactly one element. To get the first key, call allKeys to get keys, convert them to Array, and pick the the initial element:
let d = nsarray[0]["object"] as! NSDictionary
print(Array(d.allKeys)[0])