Created
October 5, 2023 17:42
-
-
Save FromMeloriWithLove/08012f7711941030ffc69da9da000710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. | |
DECLARE @string nvarchar(50) = 'нажал кабан на баклажан' | |
SET @string = REPLACE(@string, ' ', '') | |
IF @string = REVERSE(@string) | |
PRINT 'Строка является палиндромом' | |
ELSE | |
PRINT 'Строка не является палиндромом' | |
2. | |
DECLARE @string nvarchar(100) = 'Алекстандр так любит есть шаурму, что готов есть шаурму каждый день.' | |
DECLARE @word nvarchar(10) = 'шаурму' | |
DECLARE @index int = 1; | |
DECLARE @count int = 0; | |
WHILE @index > 0 | |
BEGIN | |
SET @index = CHARINDEX(@word, @string, @index); | |
IF @index > 0 | |
BEGIN | |
SET @count += 1; | |
SET @index += 1; | |
END | |
END | |
PRINT 'Общее количество слова "шаурму" в предложении состовляет: ' + CAST(@count AS nvarchar) | |
3. | |
DECLARE @string nvarchar(50) = 'Buy ViAgRA now!' | |
DECLARE @word nvarchar(10) = 'viagra' | |
SET @string = LOWER(@string) | |
DECLARE @check nvarchar(50) = @string | |
SET @check = REPLACE(@check, @word, 'spam') | |
IF @check != @string | |
PRINT 'Это спам!' | |
ПРАКТИКА | |
DECLARE @string nvarchar(50) = 'Мама мыла раму' | |
DECLARE @symbol nvarchar(1) = ' ' | |
DECLARE @start int = 1 | |
DECLARE @end int = LEN(@string) | |
DECLARE @current int = @start -- 1 | |
DECLARE @count int = 0 | |
WHILE @current <= @end | |
BEGIN | |
IF SUBSTRING(@string, @current, 1) = @symbol | |
BEGIN | |
SET @count += 1 | |
END | |
SET @current += 1 | |
END | |
SET @count += 1 | |
PRINT 'Количество слов в предложении: ' + CAST(@count AS nvarchar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment