How to search a string for another string using HTBasic [closed] - basic

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 2 years ago.
Improve this question
I am trying to create a program which will search a string for another string, and return the string directly after that string.

Use the POS function to find the substring. Give it the string to search and the string you're looking for and it will return the position it's found at:
POS( S$, T$ )
S$ is the string you're searching
T$ is the string you're looking for
Return value is the position it's found at, or 0 if not found.
The strings are treated as arrays of characters.
A$="hello"
B$=A$[3,4] ! B$ will become "ll"
C$=A$[2] ! C$ will become "ello"
To get everything following the found substring you can use something like this:
1000 DIM A$[72]
1020 A$="Hello World, & goodbye." ! String to search
1040 T$="World, " ! String to look for
1060 L=LEN(T$)
1080 PRINT A$[L+POS(A$,T$)]
1100 END
Running this should give this result:
& goodbye.

Related

Regex splitting on newline outside of quotes in VBA Macros [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 last year.
This post was edited and submitted for review last year and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have a file which contains pipe separated string, I want to split that string on new lines that are outside double quotes using Split function of VBA if possible.
File date looks like this.
fileStr = abc|hbd|hss
abd|"shs
hshs"|jdjd
hddn|hddd|sdjdd
desired ouput should be like below
Row 1 -> abc|hbd|hss
Row 2 -> abd|"shs
hshs"|jdjd
Row 3 -> hddn|hddd|sdjdd
I have tried Split(strData, vbNewLine) but its not working.
Can you please give the code snippet which I can directly use in my VBA Code.
Note: Need this in VBA Macros not in other languages
I suggest you match, rather than split, using the following regular expression (with re.Global = True).
(?=.)[^"\r\n]*(?:"(?:[^"]*")+)?[^"\r\n]*
Demo
The expression can be broken down as follows.
(?=.) # positive lookahead asserts that a character follows
[^"\r\n]* # match >= 0 characters other than double-quotes
# and line terminators
(?: # begin a non-capture group
" # match a double-quote
(?: # begin a non-capture group
[^"]* # match >= 0 characters other than double-quotes
" # match a double-quote
)+ # end inner non-capture group and execute >= 1 times
)? # end outer non-capture group and make it optional
[^"\r\n]* # match >= 0 characters other than double-quotes
The purpose of the positive lookahead at the beginning is to avoid matching empty strings.

split every single character in string. VBA.net [duplicate]

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()

How to convert a formated string into a one element tuple? [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 5 years ago.
Improve this question
It is possible to convert a single formatted string into a tuple, for example I am trying to transform a return from a function into a tuple.
E.g:
def GCcontent(self):
"Return GC content of the sequence given"
A = self.get_secuencia().count('A')
T = self.get_secuencia().count('T')
C = self.get_secuencia().count('C')
G = self.get_secuencia().count('G')
content = '{0:.2f}%'.format((G+C)*100/(A+T+G+C))
return content
The output is:
'XX.XX%'
But what I want to get is the following output:
('XX.XX%')
Is this even possible?. I tried tuple() function but it doesn't work as expected, is there another method to achieve this?
tuple([content]) will yield a 1-element tuple whose element is the string in content, but note that when printed, it appears as
('XX.XX%',)

How to count occurrences character in the string [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 8 years ago.
Improve this question
i have a string like "Nitin" write a method or logic to get output like this
N=2 I=2 T=1
means char count in string.
Try this:
string input= "asdjhrituerjkfdgf";
var resultList= input.GroupBy(e => e).Select(g => new { g.Key, Count = g.Count() }).ToList() ;

How to find words consist of the once used letters of the keyword in Lua? [duplicate]

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

Resources