How to get String with specific index - swift - arrays

For example i have String of "version/ofswift/developer". and i want print which starts from back side until the specific index like my specific index will be "/" then the answer should be "developer". What code snippet would do that, and being the most swift-like? I can't find any good practice. I hope you will help me to figure it out. Thank In Advance.

Use String method components(separatedBy:) to produce an array and then get the last element using last
let string = "version/ofswift/developer"
let lastComponent = string.components(separatedBy: "/").last

Related

Microsoft Power Automate shorten length of an unknown string

I want to shorten the length of a string to 40 Elements. I did try it with length(), last(), first()... but in order to convert it into an array I need to know the content of the string. The String I want to shorten could have any value.
Would be cool if you can share similiar problems or have a solution.
I tried to convert the string into an Array, with the split() function but I dont know the 40th Element.
By using the length function I could find out the length of the String I want to shorten.
Maybe there is something to delete the last few Elements of the string but I dont know it.
substring(variables('String'),0,39)
This should solve your problem

How to display element from an array

In the below image there is an array given to me on doing console.log
Array on doing console.log
The name of the array is commentData
if i do commentData.name i get the name
but when i do commentData.replyoncomment.Rname or commentData.replyoncomment[0].Rname
i get undefined even on commentData.replyoncomment
how do i solve this problem
if you need anything else ask me.
Update:
Thats how i turned commentData to an array
const convert = JSON.stringify(comment)
const comments = Object.values(JSON.parse(convert))
const commentData = comments
when i do commentData.name or commentData.commment
it give me the name/comment
but when i do commentData.replyoncomment i get undefined.
see the first image to understand better
on running this i get
{JSON.stringify(commentData)}
[[{"_createdAt":"2022-08-07T14:34:40Z","_id":"dqDIn547oWb3s2Y4OEwhMK","comment":"sdfanj akf js","name":"nkfndm nj","replyoncomment":[]},{"_createdAt":"2022-08-07T03:13:01Z","_id":"SD6gTXwnOmN4hstl5nkSbH","comment":"hello, I'm the admin of the webstie","name":"Mian Mohid Naeem","replyoncomment":[{"Rcomment":"gfdhhh","Rname":"gff","_createdAt":"2022-08-07T10:17:33Z"},{"Rcomment":"print("Hello world")","Rname":"programmer","_createdAt":"2022-08-07T03:13:40Z"}]}]]
anything else you need to see in the code ask me...
You should map the commentData.replyoncomment to, cause it is an array too, and React can't render arrays.
So nest an additional map to the commentData.replyoncomment.
I was willing to help you, if you have any more questions, ask me.

index of a word changed after the array was converted to lower case, and saved as a new list

so I converted my array to lower case using HashSet, and saved it to a new Array, However, this changed the index of words, and now my dialog box description of an item and a webpage that has to load on itemClick are all off. please, help!
Ihad to convert caps as i needed to get the exact corresponding data for the item on click. Thanks in advance!
If the language you're using is Java, you can simply use toLowerCase method. Try using this.
tried many different ways! but found this code from the post from 2010!! and it worked like a charm!!!!
`public static void replace(List strings){
ListIterator iterator = strings.listIterator();
while (iterator.hasNext())
{
iterator.set(iterator.next().toLowerCase());
}
}
thank you, Mathew from 2010!!!

Pass current object first Array as3

Is it possible to pass an array whilst placing the currentTarget object first in the array?
I've searched online and only found reference to index, indexOf etc but no resources on how to do this anywhere.
I can send the array no problem but it's always as first loaded, through selecting a different object it must be possible to ammend the array or splice the new object to the beginning but would really be grateful of any assistance as to how to achieve this.
Not 100% sure what you're asking, but you can use the Array::unShift(...args) method to insert an object at the beginning of an array.
Edit:
From your comment below, I think I get what you're saying. You can just swap the item you're looking for with the one at the beginning:
var index = array.indexOf(event.currentTarget);
array[index] = array[0];
array[0] = event.currentTarget;
or something similar to that anyways.

How to pass the objects of myArray?

I'm a newbie, I have gone through basics but couldn't figure this one out. I've googled so much but finally I land here.
fontFamily = [[UIFont alloc]init];
fontSize = [[NSMutableArray alloc]initWithObjects:#"10",#"15",#"20",#"25",#"30", nil ];
[text setFont: [[UIFont familyNames] size:<-----
And now, how can I pass the objects to size?
I truly don't know what your looking for. But if you are looking to access the strings you put in the array, you can do so like this:
[fontSize objectAtIndex:2]
You can put that any place you would want to put #"20" since that is what is at index 2.
You should note that you are putting string values in the array not number values.
Edit in response to comment.
You don't really want to just pass the array anywhere what you want to do is something like:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
// if calling for size component
return fontSize.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
// if calling for size component
return [fontSize objectAtIndex:row];
}
If I'm off a little I apologize, I don't use pickerViews much.

Resources