{"action":"created","comment":{"url":"https://api.github.com/repos/doomspork/elixir-school/pulls/comments/63562507","id":63562507,"diff_hunk":"@@ -0,0 +1,156 @@\n+---\n+layout: page\n+title: Ciągi znaków\n+category: basics\n+order: 14\n+lang: pl\n+---\n+\n+Czym są ciągi znaków w Elixirze, listy znaków, grafemy i jak wygląda obsługa kodowania znaków.\n+\n+{% include toc.html %}\n+\n+## Ciągi znaków\n+\n+W Elixirze ciąg znaków to nic innego jak sekwencja bajtów, przykładowo:\n+\n+```elixir\n+iex> string = <<104,101,108,108,111>>\n+\"hello\"\n+```\n+\n+>Uwaga: używając `<< >>` określamy, iż liczby w środku kompilator powinien traktować jak bajty.\n+\n+## Listy znaków\n+\n+Wewnętrznie Elixir przechowuje ciągi znaków jako sekwencja bajtów, a nie tablice znaków, posiada jednak osobny typ do\n+ reprezentowania listy znaków. Różnica polega na tym, że ciągi znaków tworzymy z użycie podwójnego cudzysłowu `\"`, a \n+ listy za pomocą pojedynczego `'`.\n+\n+Jaka jest różnica pomiędzy nimi? Każdy element na liście znaków to pojedynczy znak ASCII, popatrzmy:\n+\n+```elixir\n+iex> char_list = 'hello'\n+'hello'\n+\n+iex> Enum.reduce(char_list, \"\", fn char, acc -> acc <> to_string(char) <> \",\" end)\n+\"104,101,108,108,111,\"\n+```\n+\n+Listy znaków istnieją w Elixirze, ponieważ są wymagane przez niektóre moduły Erlanga. Na co dzień korzysta się z \n+ciągów znaków.\n+\n+## Grafemy i kodowanie\n+\n+Znaki kodowe to zwyczajne znaki Unicode, które mogą być reprezentowane przez jeden albo dwa bajty. Na przykład znaki \n+z akcentem albo tyldą: `á, ñ, è`. \n+Grafemy zwierają jeden lub wiele znaków kodowych, które będą reprezentować pojedynczy znak (literę).\n+\n+Moduł `String` ma dwie metody do ich obsługi `graphemes/1` i `codepoints/1`. Przyjrzyjmy się na przykładzie:\n+\n+```elixir\n+iex> string = \"\\u0061\\u0301\"\n+\"á\"\n+\n+iex> String.codepoints string\n+[\"a\", \"́\"]\n+\n+iex> String.graphemes string\n+[\"á\"]\n+```\n+\n+## Popularne funkcje\n+\n+Przyjrzyjmy się teraz kilku popularnym i ważnym funkcjom z modułu `String`.\n+\n+##### `length/1`\n+\n+Zwraca liczbę grafemów w ciągu znaków.\n+\n+```elixir\n+iex> String.length \"Hello\"\n+5\n+```\n+\n+##### `replace/4`\n+\n+Zwraca nowy ciąg, w którym zmieniono fragmenty pasujące do wzorca na podane w parametrze. Czwarty parametr jest \n+opcjonalny.\n+\n+```elixir\n+iex> String.replace(\"Hello\", \"e\", \"a\")\n+\"Hallo\"\n+```\n+\n+##### `duplicate/2`\n+\n+Tworzy nowy ciąg znaków będący n-krotnym powtórzeniem zadanego.\n+\n+```elixir\n+iex> String.duplicate \"Oh my \", 3\n+\"Oh my Oh my Oh my \"\n+```\n+\n+##### `split/2`\n+\n+Zwraca listę ciągów znaków, będącą wynikiem podziału ciągu według podanego wzorca. \n+\n+```elixir\n+iex> String.split(\"Hello World\", \" \")\n+[\"Hello\", \"World\"]\n+```\n+\n+## Ćwiczenia\n+\n+Let's just get in action with two simple exercises to demostrate we are ready to go with Strings!\n+Czas na dwa proste ćwiczenia by utrwalić naszą wiedzę o ciągach znaków i module `String`!\n+\n+### Anagramy\n+\n+Słowa A i B są anagramami jeżeli zmieniając kolejność liter w jednym z nich otrzymamy drugie: \n+\n+A = Wiek\n+B = Weki \n+\n+Jak można w Elixirze sprawdzić czy słowa są anagramami?\n+\n+Najprościej jest posortować litery alfabetycznie i sprawdzić czy takie listy są sobie równe. Przykładowo:\n+\n+```elixir\n+defmodule Anagram do\n+  def anagrams?(a, b) when is_binary(a) and is_binary(b) do\n+  \tsort_string(a) == sort_string(b)\n+  end\n+\n+  def sort_string(string) do\n+    string\n+    |> String.downcase\n+    |> String.graphemes\n+    |> Enum.sort\n+  end\n+end\n+```\n+\n+Przyjrzyjmy się najpierw funkcji `anagrams?/2`. Na początek sprawdzamy, czy parametry są binarny, czy też nie. W ","path":"pl/lessons/basics/strings.md","position":134,"original_position":134,"commit_id":"7ac6418fd28662275002de1ab035068b3cf84ab7","original_commit_id":"7ac6418fd28662275002de1ab035068b3cf84ab7","user":{"login":"kdebowski","id":2165223,"avatar_url":"https://avatars.githubusercontent.com/u/2165223?v=3","gravatar_id":"","url":"https://api.github.com/users/kdebowski","html_url":"https://github.com/kdebowski","followers_url":"https://api.github.com/users/kdebowski/followers","following_url":"https://api.github.com/users/kdebowski/following{/other_user}","gists_url":"https://api.github.com/users/kdebowski/gists{/gist_id}","starred_url":"https://api.github.com/users/kdebowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kdebowski/subscriptions","organizations_url":"https://api.github.com/users/kdebowski/orgs","repos_url":"https://api.github.com/users/kdebowski/repos","events_url":"https://api.github.com/users/kdebowski/events{/privacy}","received_events_url":"https://api.github.com/users/kdebowski/received_events","type":"User","site_admin":false},"body":"binarny -> binarne","created_at":"2016-05-17T17:04:58Z","updated_at":"2016-05-17T17:04:58Z","html_url":"https://github.com/doomspork/elixir-school/pull/345#discussion_r63562507","pull_request_url":"https://api.github.com/repos/doomspork/elixir-school/pulls/345","_links":{"self":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/comments/63562507"},"html":{"href":"https://github.com/doomspork/elixir-school/pull/345#discussion_r63562507"},"pull_request":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/345"}}},"pull_request":{"url":"https://api.github.com/repos/doomspork/elixir-school/pulls/345","id":68776945,"html_url":"https://github.com/doomspork/elixir-school/pull/345","diff_url":"https://github.com/doomspork/elixir-school/pull/345.diff","patch_url":"https://github.com/doomspork/elixir-school/pull/345.patch","issue_url":"https://api.github.com/repos/doomspork/elixir-school/issues/345","number":345,"state":"open","locked":false,"title":"[PL] Translation of String lesson","user":{"login":"Koziolek","id":697126,"avatar_url":"https://avatars.githubusercontent.com/u/697126?v=3","gravatar_id":"","url":"https://api.github.com/users/Koziolek","html_url":"https://github.com/Koziolek","followers_url":"https://api.github.com/users/Koziolek/followers","following_url":"https://api.github.com/users/Koziolek/following{/other_user}","gists_url":"https://api.github.com/users/Koziolek/gists{/gist_id}","starred_url":"https://api.github.com/users/Koziolek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Koziolek/subscriptions","organizations_url":"https://api.github.com/users/Koziolek/orgs","repos_url":"https://api.github.com/users/Koziolek/repos","events_url":"https://api.github.com/users/Koziolek/events{/privacy}","received_events_url":"https://api.github.com/users/Koziolek/received_events","type":"User","site_admin":false},"body":"In scope of issue #202\r\n\r\n@kdebowski have fun :)","created_at":"2016-05-03T21:19:51Z","updated_at":"2016-05-17T17:04:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b856de49e7dc336dbcd020d695d1fac6079389ff","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/doomspork/elixir-school/pulls/345/commits","review_comments_url":"https://api.github.com/repos/doomspork/elixir-school/pulls/345/comments","review_comment_url":"https://api.github.com/repos/doomspork/elixir-school/pulls/comments{/number}","comments_url":"https://api.github.com/repos/doomspork/elixir-school/issues/345/comments","statuses_url":"https://api.github.com/repos/doomspork/elixir-school/statuses/7ac6418fd28662275002de1ab035068b3cf84ab7","head":{"label":"Koziolek:issue-202-strings","ref":"issue-202-strings","sha":"7ac6418fd28662275002de1ab035068b3cf84ab7","user":{"login":"Koziolek","id":697126,"avatar_url":"https://avatars.githubusercontent.com/u/697126?v=3","gravatar_id":"","url":"https://api.github.com/users/Koziolek","html_url":"https://github.com/Koziolek","followers_url":"https://api.github.com/users/Koziolek/followers","following_url":"https://api.github.com/users/Koziolek/following{/other_user}","gists_url":"https://api.github.com/users/Koziolek/gists{/gist_id}","starred_url":"https://api.github.com/users/Koziolek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Koziolek/subscriptions","organizations_url":"https://api.github.com/users/Koziolek/orgs","repos_url":"https://api.github.com/users/Koziolek/repos","events_url":"https://api.github.com/users/Koziolek/events{/privacy}","received_events_url":"https://api.github.com/users/Koziolek/received_events","type":"User","site_admin":false},"repo":{"id":56152435,"name":"elixir-school","full_name":"Koziolek/elixir-school","owner":{"login":"Koziolek","id":697126,"avatar_url":"https://avatars.githubusercontent.com/u/697126?v=3","gravatar_id":"","url":"https://api.github.com/users/Koziolek","html_url":"https://github.com/Koziolek","followers_url":"https://api.github.com/users/Koziolek/followers","following_url":"https://api.github.com/users/Koziolek/following{/other_user}","gists_url":"https://api.github.com/users/Koziolek/gists{/gist_id}","starred_url":"https://api.github.com/users/Koziolek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Koziolek/subscriptions","organizations_url":"https://api.github.com/users/Koziolek/orgs","repos_url":"https://api.github.com/users/Koziolek/repos","events_url":"https://api.github.com/users/Koziolek/events{/privacy}","received_events_url":"https://api.github.com/users/Koziolek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Koziolek/elixir-school","description":"Lessons about the Elixir programming language","fork":true,"url":"https://api.github.com/repos/Koziolek/elixir-school","forks_url":"https://api.github.com/repos/Koziolek/elixir-school/forks","keys_url":"https://api.github.com/repos/Koziolek/elixir-school/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Koziolek/elixir-school/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Koziolek/elixir-school/teams","hooks_url":"https://api.github.com/repos/Koziolek/elixir-school/hooks","issue_events_url":"https://api.github.com/repos/Koziolek/elixir-school/issues/events{/number}","events_url":"https://api.github.com/repos/Koziolek/elixir-school/events","assignees_url":"https://api.github.com/repos/Koziolek/elixir-school/assignees{/user}","branches_url":"https://api.github.com/repos/Koziolek/elixir-school/branches{/branch}","tags_url":"https://api.github.com/repos/Koziolek/elixir-school/tags","blobs_url":"https://api.github.com/repos/Koziolek/elixir-school/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Koziolek/elixir-school/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Koziolek/elixir-school/git/refs{/sha}","trees_url":"https://api.github.com/repos/Koziolek/elixir-school/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Koziolek/elixir-school/statuses/{sha}","languages_url":"https://api.github.com/repos/Koziolek/elixir-school/languages","stargazers_url":"https://api.github.com/repos/Koziolek/elixir-school/stargazers","contributors_url":"https://api.github.com/repos/Koziolek/elixir-school/contributors","subscribers_url":"https://api.github.com/repos/Koziolek/elixir-school/subscribers","subscription_url":"https://api.github.com/repos/Koziolek/elixir-school/subscription","commits_url":"https://api.github.com/repos/Koziolek/elixir-school/commits{/sha}","git_commits_url":"https://api.github.com/repos/Koziolek/elixir-school/git/commits{/sha}","comments_url":"https://api.github.com/repos/Koziolek/elixir-school/comments{/number}","issue_comment_url":"https://api.github.com/repos/Koziolek/elixir-school/issues/comments{/number}","contents_url":"https://api.github.com/repos/Koziolek/elixir-school/contents/{+path}","compare_url":"https://api.github.com/repos/Koziolek/elixir-school/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Koziolek/elixir-school/merges","archive_url":"https://api.github.com/repos/Koziolek/elixir-school/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Koziolek/elixir-school/downloads","issues_url":"https://api.github.com/repos/Koziolek/elixir-school/issues{/number}","pulls_url":"https://api.github.com/repos/Koziolek/elixir-school/pulls{/number}","milestones_url":"https://api.github.com/repos/Koziolek/elixir-school/milestones{/number}","notifications_url":"https://api.github.com/repos/Koziolek/elixir-school/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Koziolek/elixir-school/labels{/name}","releases_url":"https://api.github.com/repos/Koziolek/elixir-school/releases{/id}","deployments_url":"https://api.github.com/repos/Koziolek/elixir-school/deployments","created_at":"2016-04-13T13:05:17Z","updated_at":"2016-04-13T13:05:18Z","pushed_at":"2016-05-16T11:34:57Z","git_url":"git://github.com/Koziolek/elixir-school.git","ssh_url":"git@github.com:Koziolek/elixir-school.git","clone_url":"https://github.com/Koziolek/elixir-school.git","svn_url":"https://github.com/Koziolek/elixir-school","homepage":"https://elixirschool.com","size":1580,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"doomspork:master","ref":"master","sha":"319d0b90b3e7172bc5e1cd363fbc1eb4906c4aeb","user":{"login":"doomspork","id":73386,"avatar_url":"https://avatars.githubusercontent.com/u/73386?v=3","gravatar_id":"","url":"https://api.github.com/users/doomspork","html_url":"https://github.com/doomspork","followers_url":"https://api.github.com/users/doomspork/followers","following_url":"https://api.github.com/users/doomspork/following{/other_user}","gists_url":"https://api.github.com/users/doomspork/gists{/gist_id}","starred_url":"https://api.github.com/users/doomspork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doomspork/subscriptions","organizations_url":"https://api.github.com/users/doomspork/orgs","repos_url":"https://api.github.com/users/doomspork/repos","events_url":"https://api.github.com/users/doomspork/events{/privacy}","received_events_url":"https://api.github.com/users/doomspork/received_events","type":"User","site_admin":false},"repo":{"id":36616176,"name":"elixir-school","full_name":"doomspork/elixir-school","owner":{"login":"doomspork","id":73386,"avatar_url":"https://avatars.githubusercontent.com/u/73386?v=3","gravatar_id":"","url":"https://api.github.com/users/doomspork","html_url":"https://github.com/doomspork","followers_url":"https://api.github.com/users/doomspork/followers","following_url":"https://api.github.com/users/doomspork/following{/other_user}","gists_url":"https://api.github.com/users/doomspork/gists{/gist_id}","starred_url":"https://api.github.com/users/doomspork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doomspork/subscriptions","organizations_url":"https://api.github.com/users/doomspork/orgs","repos_url":"https://api.github.com/users/doomspork/repos","events_url":"https://api.github.com/users/doomspork/events{/privacy}","received_events_url":"https://api.github.com/users/doomspork/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/doomspork/elixir-school","description":"Lessons about the Elixir programming language","fork":false,"url":"https://api.github.com/repos/doomspork/elixir-school","forks_url":"https://api.github.com/repos/doomspork/elixir-school/forks","keys_url":"https://api.github.com/repos/doomspork/elixir-school/keys{/key_id}","collaborators_url":"https://api.github.com/repos/doomspork/elixir-school/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/doomspork/elixir-school/teams","hooks_url":"https://api.github.com/repos/doomspork/elixir-school/hooks","issue_events_url":"https://api.github.com/repos/doomspork/elixir-school/issues/events{/number}","events_url":"https://api.github.com/repos/doomspork/elixir-school/events","assignees_url":"https://api.github.com/repos/doomspork/elixir-school/assignees{/user}","branches_url":"https://api.github.com/repos/doomspork/elixir-school/branches{/branch}","tags_url":"https://api.github.com/repos/doomspork/elixir-school/tags","blobs_url":"https://api.github.com/repos/doomspork/elixir-school/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/doomspork/elixir-school/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/doomspork/elixir-school/git/refs{/sha}","trees_url":"https://api.github.com/repos/doomspork/elixir-school/git/trees{/sha}","statuses_url":"https://api.github.com/repos/doomspork/elixir-school/statuses/{sha}","languages_url":"https://api.github.com/repos/doomspork/elixir-school/languages","stargazers_url":"https://api.github.com/repos/doomspork/elixir-school/stargazers","contributors_url":"https://api.github.com/repos/doomspork/elixir-school/contributors","subscribers_url":"https://api.github.com/repos/doomspork/elixir-school/subscribers","subscription_url":"https://api.github.com/repos/doomspork/elixir-school/subscription","commits_url":"https://api.github.com/repos/doomspork/elixir-school/commits{/sha}","git_commits_url":"https://api.github.com/repos/doomspork/elixir-school/git/commits{/sha}","comments_url":"https://api.github.com/repos/doomspork/elixir-school/comments{/number}","issue_comment_url":"https://api.github.com/repos/doomspork/elixir-school/issues/comments{/number}","contents_url":"https://api.github.com/repos/doomspork/elixir-school/contents/{+path}","compare_url":"https://api.github.com/repos/doomspork/elixir-school/compare/{base}...{head}","merges_url":"https://api.github.com/repos/doomspork/elixir-school/merges","archive_url":"https://api.github.com/repos/doomspork/elixir-school/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/doomspork/elixir-school/downloads","issues_url":"https://api.github.com/repos/doomspork/elixir-school/issues{/number}","pulls_url":"https://api.github.com/repos/doomspork/elixir-school/pulls{/number}","milestones_url":"https://api.github.com/repos/doomspork/elixir-school/milestones{/number}","notifications_url":"https://api.github.com/repos/doomspork/elixir-school/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/doomspork/elixir-school/labels{/name}","releases_url":"https://api.github.com/repos/doomspork/elixir-school/releases{/id}","deployments_url":"https://api.github.com/repos/doomspork/elixir-school/deployments","created_at":"2015-05-31T18:27:42Z","updated_at":"2016-05-14T15:32:41Z","pushed_at":"2016-05-17T15:10:21Z","git_url":"git://github.com/doomspork/elixir-school.git","ssh_url":"git@github.com:doomspork/elixir-school.git","clone_url":"https://github.com/doomspork/elixir-school.git","svn_url":"https://github.com/doomspork/elixir-school","homepage":"https://elixirschool.com","size":1741,"stargazers_count":435,"watchers_count":435,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":142,"mirror_url":null,"open_issues_count":45,"forks":142,"open_issues":45,"watchers":435,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/345"},"html":{"href":"https://github.com/doomspork/elixir-school/pull/345"},"issue":{"href":"https://api.github.com/repos/doomspork/elixir-school/issues/345"},"comments":{"href":"https://api.github.com/repos/doomspork/elixir-school/issues/345/comments"},"review_comments":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/345/comments"},"review_comment":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/doomspork/elixir-school/pulls/345/commits"},"statuses":{"href":"https://api.github.com/repos/doomspork/elixir-school/statuses/7ac6418fd28662275002de1ab035068b3cf84ab7"}}}}