Как читать, затем писать в определенную строку в консоли Visual Basic [duplicate]

Вы можете использовать эту пользовательскую библиотеку (написанную с помощью Promise) для выполнения удаленного вызова.

function $http(apiConfig) {
    return new Promise(function (resolve, reject) {
        var client = new XMLHttpRequest();
        client.open(apiConfig.method, apiConfig.url);
        client.send();
        client.onload = function () {
            if (this.status >= 200 && this.status < 300) {
                // Performs the function "resolve" when this.status is equal to 2xx.
                // Your logic here.
                resolve(this.response);
            }
            else {
                // Performs the function "reject" when this.status is different than 2xx.
                reject(this.statusText);
            }
        };
        client.onerror = function () {
            reject(this.statusText);
        };
    });
}

Пример простого использования:

$http({
    method: 'get',
    url: 'google.com'
}).then(function(response) {
    console.log(response);
}, function(error) {
    console.log(error)
});
1
задан WeSt 10 February 2015 в 17:48
поделиться

2 ответа

Если ваш текстовый файл разделен на строки, и вы хотите посмотреть только на 5-ю строку, вы можете использовать ReadAllLines для чтения строк в массив String. Технологическая линия 4 (5-я строка) и используйте WriteAllLines для повторной записи файла. В следующем примере проверяется, что файл содержит не менее 5 строк и что 5-я строка начинается с «ORIGIN»; если он заменяет строку ORIGIN «250» и перезаписывает файл.

Dim filePath As String = "E:\myFile.txt"
Dim lines() As String = System.IO.File.ReadAllLines(filePath)
If lines.Length > 4 AndAlso lines(4).StartsWith("ORIGIN ") Then
    lines(4) = "ORIGIN ""250"""
    System.IO.File.WriteAllLines(filePath, lines)
End If
2
ответ дан Blackwood 24 August 2018 в 04:56
поделиться

Вы можете просто заменить текст, а затем снова записать все обратно в файл:

Dim content As String

' read all text from the file to the content variable
content = System.IO.File.ReadAllText("E:\myFile.txt")

' replace number, text, etc. in code
content = content.Replace("<string to replace>","<replace with>")

' write new text back to the file (by completely overwriting the old content)
System.IO.File.WriteAllText("E:\myFile.txt",content)
1
ответ дан WeSt 24 August 2018 в 04:56
поделиться
Другие вопросы по тегам:

Похожие вопросы: