@@ -373,88 +373,88 @@ alert( "Widget".startsWith("Wid") ); // true, "Widget" zaczyna się od "Wid"
373
373
alert ( " Widget" .endsWith (" get" ) ); // true, "Widget" kończy się na "get"
374
374
```
375
375
376
- ## Getting a substring
376
+ ## Pobieranie podciągu
377
377
378
- There are 3 methods in JavaScript to get a substring : ` substring ` , ` substr ` and ` slice ` .
378
+ JavaScript ma 3 metody uzyskiwania podciągu : ` substring ` , ` substr ` i ` slice ` .
379
379
380
380
` str.slice(start [, end]) `
381
- : Returns the part of the string from ` start ` to (but not including) ` end ` .
381
+ : Zwraca część łańcucha od ` start ` do ` end ` (ale go nie uwzględnia) .
382
382
383
- For instance :
383
+ Na przykład :
384
384
385
385
```js run
386
386
let str = "stringify";
387
- alert( str.slice(0, 5) ); // 'strin', the substring from 0 to 5 (not including 5)
388
- alert( str.slice(0, 1) ); // 's', from 0 to 1, but not including 1, so only character at 0
387
+ alert( str.slice(0, 5) ); // 'strin', podciąg od 0 do 5 (nie uwzględnia 5)
388
+ alert( str.slice(0, 1) ); // 's', od 0 do 1, ale nie uwzględnia 1, czyli tylko jeden znak z pozycji 0
389
389
```
390
390
391
- If there is no second argument, then `slice` goes till the end of the string :
391
+ Jeśli nie ma drugiego argumentu, `slice` zwraca znaki do końca linii :
392
392
393
393
```js run
394
394
let str = "st*!*ringify*/!*";
395
- alert( str.slice(2) ); // 'ringify', from the 2nd position till the end
395
+ alert( str.slice(2) ); // 'ringify', od drugiej pozycji do końca
396
396
```
397
397
398
- Negative values for `start/end` are also possible. They mean the position is counted from the string end :
398
+ Możliwe są również ujemne wartości `start/end`. Oznacza to, że pozycja jest liczona od końca ciągu :
399
399
400
400
```js run
401
401
let str = "strin*!*gif*/!*y";
402
402
403
- // start at the 4th position from the right, end at the 1st from the right
403
+ // zaczynamy od pozycji 4 od prawej i kończymy na pozycji 1 od prawej
404
404
alert( str.slice(-4, -1) ); // 'gif'
405
405
```
406
406
407
407
` str.substring(start [, end]) `
408
- : Returns the part of the string * between * ` start ` and ` end ` .
408
+ : Zwraca część ciągu _ pomiędzy _ ` start ` i ` end ` .
409
409
410
- This is almost the same as `slice`, but it allows `start` to be greater than `end`.
410
+ Jest to prawie to samo, co `slice`, z tą różnicą, że `start` może być większe niż `end`.
411
411
412
- For instance :
412
+ Na przykład :
413
413
414
414
```js run
415
415
let str = "st*!*ring*/!*ify";
416
416
417
- // these are same for substring
417
+ // dla substring te dwa przykłady są takie same
418
418
alert( str.substring(2, 6) ); // "ring"
419
419
alert( str.substring(6, 2) ); // "ring"
420
420
421
- // ...but not for slice:
422
- alert( str.slice(2, 6) ); // "ring" (the same )
423
- alert( str.slice(6, 2) ); // "" (an empty string )
421
+ // ...ale nie dla slice:
422
+ alert( str.slice(2, 6) ); // "ring" (to samo )
423
+ alert( str.slice(6, 2) ); // "" (pusty łańcuch )
424
424
425
425
```
426
426
427
- Negative arguments are (unlike slice) not supported, they are treated as `0`.
427
+ `substring` w przeciwieństwie do ` slice` nie obsługuje wartości ujemnych i interpretuje je jako `0`.
428
428
429
429
` str.substr(start [, length]) `
430
- : Returns the part of the string from ` start ` , with the given ` length ` .
430
+ : Zwraca część ciągu od ` start ` do podanej długości ` length ` .
431
431
432
- In contrast with the previous methods, this one allows us to specify the `length` instead of the ending position :
432
+ W przeciwieństwie do poprzednich metod, ta umożliwia określenie długości `length` zamiast pozycji końcowej :
433
433
434
434
```js run
435
435
let str = "st*!*ring*/!*ify";
436
- alert( str.substr(2, 4) ); // 'ring', from the 2nd position get 4 characters
436
+ alert( str.substr(2, 4) ); // 'ring', 4 znaki liczone od drugiej pozycji
437
437
```
438
438
439
- The first argument may be negative, to count from the end :
439
+ Wartość pierwszego argumentu może być ujemna, w takim przypadku pozycja określana jest od końca :
440
440
441
441
```js run
442
442
let str = "strin*!*gi*/!*fy";
443
- alert( str.substr(-4, 2) ); // 'gi', from the 4th position get 2 characters
443
+ alert( str.substr(-4, 2) ); // 'gi', 2 znaki liczone od czwartej pozycji od końca
444
444
```
445
445
446
- Let's recap these methods to avoid any confusion :
446
+ Podsumujmy te metody, aby uniknąć nieporozumień :
447
447
448
- | method | selects ... | negatives |
448
+ | metoda | wybiera ... | wartości ujemne |
449
449
| --------| -----------| -----------|
450
- | ` slice(start, end) ` | from ` start ` to ` end ` (not including ` end ` ) | allows negatives |
451
- | ` substring(start, end) ` | between ` start ` and ` end ` | negative values mean ` 0 ` |
452
- | ` substr(start, length) ` | from ` start ` get ` length ` characters | allows negative ` start ` |
450
+ | ` slice(start, end) ` | od ` start ` do ` end ` (bez uwzględnienia ` end ` ) | zezwala |
451
+ | ` substring(start, end) ` | pomiędzy ` start ` i ` end ` | wartości ujemne oznaczają ` 0 ` |
452
+ | ` substr(start, length) ` | ` length ` znaków od ` start ` | pozwala na wartość ujemną dla ` start ` |
453
453
454
- ``` smart header="Which one to choose ?"
455
- All of them can do the job. Formally, `substr` has a minor drawback: it is described not in the core JavaScript specification, but in Annex B, which covers browser-only features that exist mainly for historical reasons. So, non-browser environments may fail to support it. But in practice it works everywhere .
454
+ ``` smart header="Którą metodę wybrać ?"
455
+ Wszystkie metody robią robotę. Formalnie `substr` ma niewielką wadę: nie jest opisana w podstawowej specyfikacji JavaScript, ale w załączniku B. Dodatek ten opisuje cechy języka używanego w przeglądarkach, które istnieją głównie ze względów historycznych. Dlatego środowiska inne niż przeglądarki mogą go nie obsługiwać. Jednak w praktyce działa wszędzie .
456
456
457
- Of the other two variants , `slice` is a little bit more flexible, it allows negative arguments and shorter to write. So, it's enough to remember solely `slice` of these three methods .
457
+ Z pozostałych dwóch opcji , `slice` jest nieco bardziej elastyczne - pozwala na użycie wartości ujemny i jest krótsze. Wystarczy więc, że spośród tych metoda zapamiętasz `slice`.
458
458
```
459
459
460
460
## Comparing strings
0 commit comments