This question already has answers here:
Split string into array of characters?
(7 answers)
Closed 3 years ago.
can you help me on this?
I have a simple string:
str="Hello World";
I want to split it as that :
array= str.Split("",System.StringSplitOptions.RemoveEmptyEntries);
result shoud be
array[0]="H"
array[1]="e"
array[2]="l"
array[3]="l"
array[4]="o"
array[5]="W"
array[6]="o"
...
But I don't know to "wildcard" the separator..
Any Idea on this ?
Thanks
?
Just use String.ToCharArray():
SomeArray = str.ToCharArray()
Related
This question already has answers here:
How do you print a dollar sign $ in Dart
(2 answers)
Closed 4 years ago.
I'm currently creating an simple application with flutter(Dart). And when i want to create the AppBar widget, i cant give it names with '$'. Because, same like Kotlin..Dart is using '$' for summoning an identifier.
Any solution?
var _appbar = AppBar(
title: Text("How I Made $100"), //$ is the error
);
The dollar sign is a special character, so if you want it to be ignored you have to escape it with a \.
For example:
void main() {
print("This string contains a dollar \$ign");
}
See this gist.
This question already has answers here:
How do I replace all occurrences of a string in JavaScript?
(78 answers)
Closed 6 years ago.
I would like to replace multiple words from below string:
\njava developer\n
How do I replace \n from start and \n from last from above string?
I used
replace('\n', '')
but it replace first \n only.
If you want to replace all \n without calling replace in a loop you have to use a regular expression. You can use it like this:
var test = "\njava developer\n";
var result = test.replace(/\n/g, '');
the g in the regular expression means replace all occurrences.
Hope this helps.
Thanks vincent!
It works for me.
I implement like this
stringToChange.toLowerCase().toString().replace(/[<b></b>\n]/g,'')
to replace
<\b>, <b> and \n
all multiple occurrences.
This question already has answers here:
How do I check if a string contains another string in Swift?
(28 answers)
Closed 7 years ago.
The answer in this question: How do I check if a string contains another string in Swift?
No longer works.
var string = "hello Swift"
if string.rangeOfString("Swift") != nil{
println("exists")
}
Will get you:
error: value of type 'String' has no member 'rangeOfString'
What is the new way to do this?
Import Foundation and you will be able to call rangeOfString.
This question already has answers here:
How to get the last N records in mongodb?
(16 answers)
Closed 7 years ago.
I can't find the answer. I have a query that can return many answer and I want to get the last one. How to do it?
db.users.find({username: "bob", sort: {createdAt: -1}}).first()
I would like something like this.
do this to get last N records :
function last(N) {
return db.collection.find().skip(db.collection.count() - N);
}
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I find the words consist of the letters inside the keyword in Lua?
I am trying to find words consist of letters inside the keyword. However, the letters shouldn't be used again once it's detected that it's inside the word.
i keep the words in the dictionary.
For example I have the keyword: "asdasdas"
My code says hi in these conditions
consistLetters("asdasdas","asdas")
consistLetters("asdasdas","sad")
consistLetters("asdasdas","sss")
However it also says hi when i consume all of the "s" in the keyword which is not what i want:
consistLetters("asdasdas","ssss")
How to stop this? Thank you.
EDIT: I solved my problem and shared it as an answer. I hope it'll be helpful.
Here is my code:
function consistLetters(keyword,word)
keywordletters={ }
wordletters= { }
local found=false
findLetters(keyword,keywordletters)
findLetters(word,wordletters)
for i=1, #wordletters,1 do
for j=1, #keywordletters,1 do
if(keywordletters[j]~="") then
if(wordletters[i]==keywordletters[j]) then
keywordletters[j]=""
found=true;
break
end
end
end
if found~=true then
return false
end
found=false;
end
end