Basic4android how to explode a string and convert to array - basic4android

I am trying to separate the characters of string.
Dim res As String
res = "1+2+3+4+")
tempArr = Regex.split("\+", res)
I am using this code to convert the string into array.Is it correct ? and also i need to know the count of the array. How it possible to get the count of the array ?

Your code is correct.
Dim res As String = "1+2+3+4+"
Dim numbers() As String = Regex.Split("\+", res)
Log(numbers.Length)
For Each n As String In Numbers
Log(n)
Next

Related

apply encoding algorithm from original and encoded string onto new string

I have an ecoded string and the original string.
Is it possible to apply the used algorithm without knowing it onto another string?
Those are the strings:
num1 = "1193"
encoded1 = "7ecb452bee6a1b227bc3"
num2 = "1259"
encoded2 = "7ecfb3daff5acd1b7ab2"
If you know how these strings were encrypted that would also make it easier :D

flutter: change strings letters from the letters from list 1 to the letters from list 2

I am trying to change a string letters from the letters from list 1 to the letters from list 2
and I couldn't find a way to do it
this is my 2 lists
List En = ["A","A","B","G","D","R","S","C","T","E","F","K","L","M","N","H","W","Y","Y"];
List Ar = ["ا","أ","ب","ج","د","ر","س","ص","ط","ع","ف","ق","ل","م","ن","ه","و","ى","ي"];
so if the string was "abc" for example it would get the equivalent of the chars A B C from list 1 and then translate them to the same indexes in list 2
I don't know why others are happy with linear searches of lists. To me, that screams for setting up a map one time, and using it repeatedly. Here's what I whipped up in DartPad:
void main() {
var En = ['a', 'b', 'c'];
var Ar = ['1', '2', '3'];
var en2ar = Map<String, String>.fromIterables(En, Ar);
print(en2ar);
var text = 'abcd';
var output =
text.replaceAllMapped(RegExp('.'), (Match m) => en2ar[m.group(0)] ?? '');
print('$text => $output');
}
you can use this function:
setText(){
String input = 'ABC';
List text = input.split('');
String output = '';
List En = ["A","A","B","G","D","R","S","C","T","E","F","K","L","M","N","H","W","Y","Y"];
List Ar = ["ا","أ","ب","ج","د","ر","س","ص","ط","ع","ف","ق","ل","م","ن","ه","و","ى","ي"];
text.forEach((item){
int index = En.indexWhere((element) => element == item);
if(index != -1){
output = output + Ar[index];
}
});
return output;
}
using the indexWhere method you can find the index of a certain char in array a then replace the char with the element at the same index in array b
I would use this flow
cycle the characters of the string you want to repalce
for every character you get the index of the array a
add the item at the same index in the array b to a "result" string
You should now have a string "result" with the characters replaced

Swift 5 split string at integer index

It used to be you could use substring to get a portion of a string. That has been deprecated in favor on string index. But I can't seem to make a string index out of integers.
var str = "hellooo"
let newindex = str.index(after: 3)
str = str[newindex...str.endIndex]
No matter what the string is, I want the second 3 characters. So and str would contain "loo". How can I do this?
Drop the first three characters and the get the remaining first three characters
let str = "helloo"
let secondThreeCharacters = String(str.dropFirst(3).prefix(3))
You might add some code to handle the case if there are less than 6 characters in the string

How to use split method with string containing brackets?

I have a string that contains some data. Data is separated like this:
var stringData = (SomeWordsWithSpacesInBetween) 0 (SomeWordsWithSpaceInBetween) 1 ...
I want to be able to extract data between the brackets and numbers between the words in brackets as such:
stringData.split( some way to split them)[0] = SomeWordsWithSpacesInBetween;
stringData.split(some way to split them)[1] = 0;
How to split them this way?
var s = '(Some Words With Spaces InBetween) 0 (SomeWordsWithSpaceInBetween) 1';
var r = RegExp(r'\(((\w+ ?)*)\) (\d+) ?').allMatches(s).expand((e) => [e[1], e[3]]);
You can do it using regular expression. Here is an example.
List<String>getStringList(){
String abc = '(SomeWordsWithSpacesInBetween) 0 (SomeWordsWithSpaceInBetween) 1 (SomeWordsWithSpaceInBetween)';
List<String> myList = new List();
RegExp exp = new RegExp(r"\) (\d+) \(");
myList = abc.split(exp);
print('${myList}');
return myList;
}

what is the substr? in the systemverilog

Int fd;
String str;
fd = $fopen(path, "r");
Status= $fgets(str, fd);
cm = str.substr(0,1);
cm1= str.substr(0,0);
I want to know what is substr function? What is the purpose above that??
The substr function returns a new string that is a substring formed by characters in position i through j of str. Very similar to examples posted here.
module test;
string str = "Test";
initial
$display(str.substr(0,1));
endmodule
The output will be:
>> Te
As you can see in section 6.16.8, IEEE SystemVerilog Standard 1800-2012.
substr function, as it name suggests, subtracts, or takes a chunk from a bigger string, in systemverilog.
Example:
stri0 = "my_lago";
stri1 = stri0.substr(1,5);
$display("This will give stri1 = %s" , stri1);
....
OUTPUT :- This will give stri1 = y_lag
Substring: This method extracts strings. It needs the Position of the substring ( start index, length). It then returns a new string with the characters in that range.
C# program Substring
using System;
class Program
{
static void Main()
{
string input = "ManCatDog";
// Get Middle three characters.
string subString = input.Substring(3, 6);
Console.WriteLine("SubString: {0}", subString);
}
}
Output
Substring: Cat