Aufgabe_1.R
von tegula- SNIPPET_DESC:
- Bitte Dateinamensendung .txt entfernen.
- SNIPPET_CREATION_TIME:
- 07.09.2022 15:55:49
- SNIPPET_PRUNE_TIME:
- Unendlich
- SNIPPET_TEXT:
-
- # Aufgabe 1: Bestimme, wie viele Buchstaben, die URL des dfde-Unterforums "Softwareentwicklung und -paketierung, Scripting" (<https://debianforum.de/forum/viewforum.php?f=34>) enthält. Zähle einmal mit und einmal ohne die Angabe des Protokolls ("https").
- #' ----------------------------
- #' ----------------------------
- # Tidyverse laden
- library(tidyverse)
- #' ----------------------------
- #' ----------------------------
- # (Hilfs-)funktionen definieren
- ## Funktion definieren: Handelt es sich um eine HTTP-Url?
- is_http_url <- function(string) {
- if (is.character(string)) {
- string %>%
- stringr::str_detect("^https://\\S+\\.\\S+$") %>%
- return()
- }
- else {
- return(NA)
- }
- }
- ## Funktion definieren: Protokollangabe "http://" bzw. https:// entfernen
- cut_http <- function(string) {
- if ((is_http_url(string))) {
- match_matrix <- string %>%
- stringr::str_match("^https?://(.*)$")
- # Die Matches und zur ersten (und in diesem Fall auch einzigen) Gruppe (Teilausdruck) befinden sich in match_matrix[2].
- return(match_matrix[2])
- }
- else {
- return(NA)
- }
- }
- #' ----------------------------
- #' ----------------------------
- # URL zum Forum "Softwareentwicklung und -paketierung, Scripting" im Workspace speichern
- url_dfde_skripting <- "https://debianforum.de/forum/viewforum.php?f=34"
- #' ----------------------------
- #' ----------------------------
- # Buchstaben (inklusive http bzw. https) zählen :
- if (is_http_url(url_dfde_skripting)) {
- url_dfde_skripting %>%
- str_count(pattern = "[:alpha:]")
- } else {
- print(NA)
- }
- #' ----------------------------
- #' ----------------------------
- # Buchstaben (abzüglich http bzw. htpps) zählen:
- url_dfde_skripting %>%
- cut_http() %>%
- str_count(pattern = "[:alpha:]")
- #
Quellcode
Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN