Vb6: Separating Tab Delimited Text - parsing

I have a file with several thousand rows and several columns separated with tabs What I'd like to do is loop through each individually, Drop the columns into an array so that I can place them in another application individually, then move onto the next line. Unfortunately I got about as far as this:
Open mytextfile.txt For Input As #FileHandle
Do While Not EOF(FileHandle)
Line Input #FileHandle, IndividualLine
StringToBreakup = IndividualLine
Loop
So how would I go about breaking individual line up into an array

Dim str() as String
Open mytextfile.txt For Input As #FileHandle
Do While Not EOF(FileHandle)
Line Input #FileHandle, IndividualLine
str = Split(IndividualLine, vbTab)
Debug.Print str(0) 'First array element
Loop
To clarify: I would avoid the use of Variants and use vbTab.

Use the split command
Dim StringArray as Variant
Open mytextfile.txt For Input As #FileHandle
Do While Not EOF(FileHandle)
Line Input #FileHandle, IndividualLine
StringToBreakup = IndividualLine
StringArray = Split(StringToBreakup, CHR(9))
Process array here...
Loop

Related

How to reverse the words in the string in automation anywhere

I am trying to reverse the string For Example string s= "Hello Robot Process Automation" will be changed to String s="Automation Process Robot Hello" in automation anywhere.
I tried below steps:-
Reverse the sentence(it reverses the words and alphabets in words as well).
2.Split the sentence and put into list variable
used loop and in same loop i reversed again the alphabets so now the sentence will be like "Automation" "Process" "Robot" "Hello" into one list
4 I am not getting next step after this(joining of these words).
Please help.
For reversing the string as per above requirement, below are the steps:
Create a variable for storing the reversed string called vReversedString
Reverse the given string i.e from above string the output should be noitamotuA ssecorP toboR olleH
Split the reversed string by space deliminator and store in my-list-variable
Loop through my-list-variable
Reverse the each element through the loop. For example, In this case the first element is noitamotuA by reversing this you'll be getting Automation as an output, store it to system variable clipboard or create a new variable to hold each element.
Concatenate and store to vReversedString = $vReversedString$ $clipboard$

splitting address with - using split() results in wierd 5 digits

kinda stumped with the split function, was wondering if someone can help me out.
I have a list of addresses where I'm trying to split the number and street name. These addresses have hypens in them so for example.
10-09 Main St
So i used =SPLIT(A1, " ") <- Column A has all the addresses.
The result i get is = 43017 Main St
I could use the menu tab Data >> Split text to columns but I'm trying to automate it using a script. Is there a way to force the split function to treat the data as text and not as a number?
Thank you in advance
This will work with these two user defined functions. Assuming your address is in A1.
function nbr(range) {
var addr = range.split(" ");
return addr[0];// just the nbr
}
function street(range) {
var addr = range.split(" ");
var array=[]
for(var i=1;i<addr.length;i++){
array.push(addr[i]) //create an array of split addr starting with second element
}
return array.toString().replace(/,/g," ")// convert array to string and replace all commas with soaces
}
In B1 put =nbr(A1) and in C1 put =street(A1)
Have you tried changing the column types to flat text? I was more-or-less able to replicate the behaviour when I set the column type to number, but when I changed the type to flat text, it behaved as expected.
Try Layout -> Number -> Flat text.
(Since I'm Dutch, the options might be named slightly different - apologies for that)

How to combine two strings in Fortran

Here's an example in python3 of what I want to do in Fortran:
str1 = "Hello"
str2 = " World!"
print(str1 + str2)
# And then the result would be "Hello World!"
When I do:
print "(A)", str1, str2
It puts it on a separate line. If anyone knows how to help please answer.
The literal answer to string concatenation, using the // operator, is given in another answer. Note, particularly, that you likely want to TRIM the first argument.
But there is another interesting concept your question raises, and that is format reversion.
With the format (A) we have one format item. In the output list str1, str2 we have two output items. In a general output statement we apply each format item (with repeat counts) to a corresponding output item. So, str1 is processed with the first format item A, and a string appears.
Come the second output item str2 we've already used the single format item, reaching the end of the format item list. The result is that we see this format reversion: that is, we go back to the first item in the list. After, crucially, we start a new line.
So, if we just want to print those two items to one line (with no space or blank line between them) we could use (neglecting trimming for clarity)
print "(A)", str1//str2
or we could use a format which hasn't this reversion
print "(2A)", str1, str2
print "(A, A)", str1, str2
The first concatenates the two character variables to give one, longer, which is then printed as a single output item. The second prints both individually.
Coming to your particular example
character(12), parameter :: str1="Hello" ! Intentionally longer - trailing blanks
character(12), parameter :: str2=" World!"
print "(2A)", TRIM(str1), TRIM(str2)
end
will have output like
Hello World!
with that middle space because TRIM won't remove the leading space from str2. More widely, though we won't have the leading space there for us, and we want to add it in the output.
Naturally, concatenation still works (I'm back to assuming no-trimming)
character(*), parameter :: str1="Hello" ! No trailing blank
character(*), parameter :: str2="World!"
print "(A)", str1//" "//str2
end
but we can choose our format, using the X edit descriptor, to add a space
print "(2(A,1X))", str1, str2
print "(A,1X,A)", str1, str2
print "(2(A,:,1X))", str1, str2
where this final one has the useful colon edit descriptor (outside scope of this answer).
Probably close to what you want:
Concatenate two strings in Fortran
zz = trim(xx) // trim(yy)
More info
Bing
It looks like this is covered but another useful feature, if you want to print a lot of data on the same line is the following:
character(len=32),dimension(100) :: str
do i=1,100
write(*,fmt="(A)", advance='no') str(i)
end do
write(*,*) ! to go to the next line when you are done
This will print 100 characters on the same line because of advance='no'
You can use another variable to put those into it, and write those two strings in that new variable:
Program combineString
character(len=100) :: text1, text2, text
text1 = "Hello,"
text2 = "My name is X"
write(text,'(A6, X, A20)') text1, text2
write(*,*) text
End Program
And output is:
Hello, My name is X

from list to string and back to list

I have read a multiline file and converted it to a list with the following code:
Lines = string:tokens(erlang:binary_to_list(Binary), "\n"),
I converted it to a string to do some work on it:
Flat = string:join(Lines, "\r\n"),
I finished working on the string and now I need to convert it back to a multiline list, I tried to repeat the first snippet shown above but that never worked, I tried string:join and that didnt work.. how do i convert it back to a list just like it used to be (although now modified)?
Well that depends on the modifications you made on the flattened string.
string:tokens/2 will always explode a string using the separator you provide. So as long as your transformation preserves a specific string as separator between the individual substrings there should be no problem.
However, if you do something more elaborate and destructive in your transformation then the only way is to iterate on the string manually and construct the individual substrings.
Your first snippet above contains a call to erlang:binary_to_list/1 which first converts a binary to a string (list) which you then split with the call to string:tokens/2 which then join together with string:join/2. The result of doing the tokens then join as you have written it seems to be to convert it from a string containing lines separated by \n into one containing lines separated by \r\n. N.B. that this is a flat list of characters.
Is this what you intended?
What you should do now depends on what you mean by "I need to convert it back to a multiline list". Do you mean everything in a single list of characters (string), or in a nested list of lines where each line is a list of characters (string). I.e. if you ended up with
"here is line 1\r\nhere is line 2\r\nhere is line 3\r\n"
this already is a multiline line list, or do you mean
["here is line 1","here is line 2","here is line 3"]
Note that each "string" is itself a list of characters. What do you intend to do with it afterwards?
You have your terms confused. A string in any language is a sequence of integer values corresponding to a human-readable characters. Whether the representation of the value is a binary or a list does not matter, both are technically strings because of the data they contain.
That being said, you converted a binary string to a list string in your first set of instructions. To convert a list into a binary, you can call erlang:list_to_binary/1, or erlang:iolist_to_binary/1 if your list is not flat. For instance:
BinString = <<"this\nis\na\nstring">>.
ListString = "this\nis\na\nstring" = binary_to_list(BinString).
Words = ["this", "is", "a", "string"] = string:tokens(ListString, "\n").
<<"thisisastring">> = iolist_to_binary(Words).
Rejoined = "this\r\nis\r\na\r\nstring" = string:join(Words, "\r\n").
BinAgain = <<"this\r\nis\r\na\r\nstring">> = list_to_binary(Rejoined).
For your reference, the string module always expects a flat list (e.g., "this is a string", but not ["this", "is", "a", "string"]), except for string:join, which takes a list of flat strings.

Haskell -> After parsing how to work with strings

Hello
after doing the parsing with a script in Haskell I got a file with the 'appearance' of lists of strings. However when I call the file content with the function getContents or hGetContents, ie, reading the contents I get something like: String with lines (schematically what I want is: "[" aaa "," bbb "" ccc "]" -> ["aaa", "bbb" "ccc"]). I have tried with the read function but without results. I need to work with these lists of strings to concatenating them all in a single list.
I'm using the lines function, but I think it only 'works' one line at a time, doesn't it?
What I need is a function that verify if an element of a line is repeted on other line. If I could have a list of a list of strings it could be easier (but what I have is a line of a string that looks like a list of strings)
Regards
Thanks.
I have tried with the read function but without results
Just tested, and it works fine:
Prelude> read "[\"aaa\",\"bbb\",\"ccc\"]" :: [String]
["aaa","bbb","ccc"]
Note that you need to give the return type explicitly, since it can't be determined from the type of the argument.
I think the function you are looking for is the lines function from Data.List (reexported by the Prelude) that breaks up a multi-line string into a list of strings.
in my understanding, what you can do is
create a function that receives a list of lists, each list is a line of the entire string, of the argument passed in, and checks if a element of a line occurs in other line.
then, this function passes the entire string, separated by lines using [lines][1].

Resources