C# UWP textfile to list of strings - list

I'm creating a UWP application (latest windows IoT) for my raspberry.
I'm trying to get a list of strings from a .txtfile located in the project folder under a map called Words.
This is my code so far.
public async void GenereerGokWoord(int character)
{
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(
new Uri("ms-appx:///Words//5-letterwoorden.txt")
);
}
By setting a breakpoint at the end of the } I can confirm that this code can find the .txt file.
But now I don't know how to get a list of strings from this point on.
The .txt file looks like things
word 1
word 2
word 3

If you want contents of file as a List with each line as an Item, Use FileIO.ReadLinesAsync()
IList<string> data = await FileIO.ReadLinesAsync(file);
List<string> finallist = data.ToList();
Your finallist should contain all words as List.

Related

Get content from txt file and put it in a list Flutter/Dart

this is my first question here on stackoverflow. Before i get into the question itself, i want to point out that i'm a beginner on Flutter and Dart and have no previous experience in mobile development.
Now, as the title says i'm having some issues while trying to extract the content of a text file and store the individual names inside the indexes of a list. The end goal of my application is to print a never ending list of these names, each separated to another by a comma. For example:
top model,
torcitóre,
torcolière,
tornitóre,
tosacàni,
tossicòlogo,
tour operator,
tracciatóre,
tranvière,
trattorìsta,
trattóre²,
trebbiatóre,
trecciaiòlo,
trevière,
tributarìsta,
trinciatóre,
trivellatóre,
truccatóre,
tubìsta,
turnìsta,
The text file, named jobs.txt contains more than a 1000+ italian job names. After several hours searching, all i have here is this (got from another user):
import 'dart:async';
import 'dart:convert';
import 'dart:io';
void main(List<String> arguments) {
try {
final _jobs = File('jobs.txt');
List<String> lines = _jobs.readAsLinesSync(encoding: ascii);
for (var l in lines) print(l);
} catch (Exception) {
print(Exception.toString());
}
}
jobs.txt is inside the same directory as the dart file, which is bin.
While trying to give the _jobs variable the relative path:
FileSystemException: Cannot open file, path = 'binjobs.txt' (OS Error: Impossibile trovare il file specificato.
, errno = 2)
With absolute path:
FileSystemException: Cannot open file, path = 'C:UsersUserDesktopdartdart_application_injobs.txt' (OS Error: La sintassi del nome del file, della directory o del volume non è corretta.
, errno = 123)
For reasons i don't know, if that even matters, in the path specified in the error message, the \ look like they don't even exist.
By the way, this is my project structure:
project structure
If your solution includes the usage of the Future class or async-await keywords, i'll be thankful if you could explain me how they work.
UPDATE: Look in the comments for the full solution to this issue. The verified answer isn't the full solution.
Create an assets folder in your project, in your pubspec.yaml specify the asset (make sure it's in your assets folder, that the file exists and is readable)
flutter:
assets:
- assets/jobs.txt
Now you can access your text file like so -
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;
Future<String> loadAsset() async {
return await rootBundle.loadString('assets/jobs.txt');
}
When the function returns your text, you can split it by commas and loop through all the jobs as you wish
try using rootBundle
pubspec.yaml
assets:
- text_file/
import 'package:flutter/services.dart' show rootBundle;
Future<String> getData() async {
try {
return await rootBundle.loadString('text_file/four_words.txt');
} catch (e) {
throw (e.toString());
}
}

Get filename in Dynamics Ax

I need to extract a file name from complete path and I see it strange that I when I split the path, I need to iterate through the list to get the file name. Why can't I just get the value simply by calling myList(3) as in DotNet, instead of having to instantiate an iterator, then loop through the records.
Here is my code;
List strlist=new List(Types::String);
strlist = strSplit(CompletePath, #"\");
After doing this I should have a list of all the different parts.
Is there any simple form to read the list, like FileName = strlist[2]; instead of having to do the below;
iterator = new ListIterator(strlist);
while(iterator.more())
{
FileName = iterator.value();
if (_Value == "myFile")
{
_NotFound=boolean::false;
}
Here again, if at that very moment, I don't know the file name, how do I check?
Global::fileNameSplit(fileName)
returns a container [path, file name, extension]
Should be used over the .NET methods recommended by Matej.
Use System.IO.Path::GetFileName(CompletePath) or System.IO.Path::GetFileNameWithoutExtension.

How to search for a specific word in nodejs and return the coloun number

I am trying to find out where the source ip colon is there in the excel file i want it to search in the whole file rather than me manually telling in the code .
How to do it i want to know weather there is possibility and any modules available for that work
My nodejs code
var Regex = require("regex");
var regex = new Regex(/(S|s)(O|o)(U|u)(R|r)(C|c)(E|e)( )*(I|i)(P|p)/);
var parseXlsx = require('excel');
parseXlsx('ISFWREQ-373_update.xlsx', function(err, data) {
console.log(regex.test(data[5][0]));
});

ActiveQt: Activate an already open word document

I am trying to write to an open word document using activeQt. I am trying to activate my word document, but i cant get it to work.
I can do this in VBA very easily:
Documents("my.doc").Activate
but not in Qt, this is what i have tried:
wordApplication = new QAxObject("Word.Application");
doc = wordApplication->querySubObject("Documents()","my.doc");
doc->dynamicCall("Activate()");
Documents() is supposed to contain all the open word documents, but for me it is empty for some reason.
I found the solution to my problem, by using the setControl function with the UUID for word I was able to access a word document that was already opened.
QAxObject* wordApplication;
QAxObject* doc;
wordApplication = new QAxObject(this);
wordApplication->setControl(("{000209FF-0000-0000-C000-000000000046}&"));
doc = wordApplication->querySubObject("Documents()","my.doc");

SearchOption.AllDirectories and ignore access errors?

string[] files = Directory.GetFiles(tb_dir.Text, tb_filter.Text, SearchOption.AllDirectories);
I'm trying to search through a directory and all sub directory to find some file. I keep running into an error with the current code that the second it sees something it can't get into it breaks
In this application that doesn't matter i would rather it just move on. Is there anyway to bypass this code from dumping out everytime?
Thanks
Crash893
You could do something like this:
List<string> GetFiles(string topDirectory, string filter)
{
List<string> list = new List<string>();
list.AddRange(Directory.GetFiles(topDirectory, filter));
foreach (string directory in Directory.GetDirectories(topDirectory))
{
list.AddRange(GetFiles(directory));
}
return list;
}
and call it with:
List<string> files = GetFiles(tb_dir.Text, tb_filter.Text);
You could convert the list of files into an array, of course.
You would have to add try catch blocks to handle the UnauthorizedAccessException.