הצטרפו לקבוצות שלנו לקבלת עדכונים מרוכזים פעם בשבוע:

ווטסאפ:
http://wa.dwh.co.il
טלגרם:
http://telegram.dwh.co.il

פונקציה לסידור עברית אנגלית

More
17 years 3 months ago #3550 by עידן8
שלום רב!
ראשית אני דיי חדש באתר - שמעתי רבות וטובות עליו והחלטתי גם לקחת חלק בחוויה :)
אז ככה אני עובד עם SSIS 2005 ובתהליך הגזירה מה ERP נתקלתי בבעיה שכשקיימים שדות שבהם יש נתונים באותו תא גם בעברית וגם באנגלית אז משום מה האנגלית מתהפכת
אם לדוגמא הנתונים בתא המקור היו : " Sector  חנות " אני מקבל את הנתונים לאחר המשיכה כך
" rotcoS חנות " , בניתי פונקציה ב SQL שמצליחה להפוך את האנגלית ולסדר את המילה באופן תקין אך כאשר מצורף מספר למחרוזת הכל מתהפך בסדר לא הגיוני ( כמו למשל : " חנות  Sector 10.2.2008  " - עם כזו מחרוזת הפונקציה לא מסוגלת להתמודד)
שאלתי היא האם מישהו יודע על קיומה של פונקציה \ כתב פונקציה ש"מסדרת" את הנתונים כמו שצריך.
אני מאמין שהבעיה הזו היא יחסית דיי שכיחה(למרות שחיפשתי ברשת פונקציה כזו ולא  מצאתי משהו)
אשמח לכל עזרה שהיא.
בתודה עידן.

Please התחברות to join the conversation.

More
17 years 3 months ago #3558 by eldad
הקוד הבא הופך את האנגלית ולא את העברית
תכניס את זה לתוך פנקציה וז אמור לסדר את רוב הבעיות


declare  @NAME VARCHAR(300)
set @name = 'rotcoS חנות'
      DECLARE @POS INT
      DECLARE @HebrewWord varchar(200)
      DECLARE @EnglishWord Varchar(200)
      DECLARE @NewName Varchar(200)
      DECLARE @Found int

-- initialazation
set @HebrewWord = ''
set @EnglishWord = ''
set @Found = 0
set @NewName = ''
set @NAME  = ltrim(Rtrim(@NAME))

      SELECT @POS = 1
      WHILE @POS <= LEN(@NAME)
            --2
      BEGIN           
            if (ASCII(SUBSTRING(@NAME,@POS,1)) <> 32)
            begin
                  IF (ASCII(SUBSTRING(@NAME,@POS,1)) < 224)
                  begin
                    SELECT @NAME = STUFF(@NAME, @POS, 1 , CHAR(ASCII(SUBSTRING(@NAME,@POS,1))))
                        set @EnglishWord = @EnglishWord + SUBSTRING(@NAME,@POS,1)
                        set @Found = 0
                        --set @HebrewWord = ''
                        --end if
                  end 
                  else               
                  begin
                        set @HebrewWord = @HebrewWord + SUBSTRING(@NAME,@POS,1)
                        set @Found = 1
                        --set @EnglishWord = ''
                              --end else
                  end
                      set @NewName =  reverse(@EnglishWord) +  ' ' + @HebrewWord

                  IF SUBSTRING(@NAME,@POS,1)= ''''
                  begin
                          SELECT @NAME = STUFF(@NAME, @POS, 1 , '`')     
                              --end if
                  end

            --end if (ASCII(SUBSTRING(@NAME,@POS,1)) <> 32)
      end
      else
      begin
            set @EnglishWord = @EnglishWord + ' '
            set @HebrewWord = @HebrewWord + ' '
            --end else
      end
                  SELECT @POS = @POS + 1
      --end while @POS <= LEN(@NAME)

    END
      select  (ltrim(rtrim(@NewName))) --REVERSE (@HebrewWord) +@EnglishWord

Please התחברות to join the conversation.

More
17 years 3 months ago #3567 by עידן8
ראשית כל תודה על הפונקציה.
בדקתי אותה וכמו הפונקציה שבניתי היא לא מתמודדת טוב עם תאריכים (המספר מתהפך\מתחרבש)
בינתיים כתבתי פונקציה ב VB שהופכת רק את העברית ,המספרים  והאותיות באנגלית נשארות כמו במחרוזת המקורית.הקוד מפריד את המילים רקבאמצעות " " - רווח הקיים בין המילים במחרוזת.
להלן הקוד - לשימושכם :

Public Class Form1

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        Dim Word, StrEng, Str As String
        Dim i, z, k, counter As Integer
        Dim Ch As String


        'סופר את מספר הרווחים במחרוזת
        Word = txt1.Text
        Ch = Mid(Word, 1, 1)
        counter = 0
        For i = 1 To Len(Word)
            If Ch = " " Then
                counter = counter + 1
            End If
            Ch = Mid(Word, i, 1)
        Next


        StrEng = ""
        i = 1
        Ch = Mid(Word, i, 1)
        For z = 0 To counter
            Str = ""
            k = Len(Word)
            Do While (Ch <> " ") 'Or (k <> i)
                Ch = Mid(Word, i, 1)
                Str = Str + Ch
                i = i + 1
                If k = i - 1 Then
                    GoTo Here
                End If
            Loop

Here:      If ((Mid(Str, 1, 1)) >= "א") And ((Mid(Str, 1, 1) <= "ת")) Then
                Str = StrReverse(Str)
            End If
            StrEng = StrEng + Str
            Ch = Mid(Word, i + 1, 1)
            'i = i + 1
        Next

     


        'If ((Mid((arr(0)), 1, 1)) >= "א") And ((Mid((arr(0)), 1, 1) <= "ת")) Then

        '    StrHeb = StrReverse(arr(0))

        'End If
        'If ((Mid((arr(0)), 1, 1)) >= "a") And ((Mid((arr(0)), 1, 1) <= "z")) Or ((Mid((arr(0)), 1, 1)) >= "A") And ((Mid((arr(0)), 1, 1) <= "Z")) Then

        '    StrEng = StrReverse(arr(0))

        'End If

        MsgBox(StrEng)

    End Sub
End Class


Please התחברות to join the conversation.

More
17 years 3 months ago #3572 by עידן8
ובגרסת ה SQL למי שמעוניין :


ALTER FUNCTION [dbo].[Heb_Reverse_New]
(@st nvarchar(100))
RETURNS nvarchar(100)
AS
BEGIN
declare @StrEng nvarchar(100)
declare @Word nvarchar(50)
declare @str nvarchar(50)
declare @Ch nvarchar(50)
declare @i smallint
declare @z smallint
declare @k smallint
declare @counter smallint
set @Word = @st
set @Word = LTRIM(RTRIM(@Word))
--set @Word = 'gagsg אמרה והלכה 10.02.2008 gdgdg '
set @Ch = left(@Word,1)
set @counter = 0
set @i = 1

--Count the number of Spaces
While @i <= Len(@Word)
BEGIN
if @Ch = ' '
Begin
set @Counter = @Counter + 1
End
Set @i = @i +1
set @Ch = substring(@Word,@i,1)
END
--select @Counter
set @StrEng = ''
Set @i = 1
set @Ch = substring(@Word,@i,1)
Set @z = 0
WHILE @z <= @Counter
BEGIN
set @Str = ''
Set @k = Len(@word)
WHILE (@Ch <> ' ') --Or (@k <> @i)
BEGIN
Set @Ch = substring(@Word,@i,1)
Set @Str = @Str + @Ch
Set @i = @i + 1
If @k = @i - 1
BEGIN
BREAK
END
END
    If ((Substring(@Str, 1, 1)) >= 'א') And ((Substring(@Str, 1, 1) <= 'ת'))
BEGIN
set @Str = Reverse(@Str)
END
    set @StrEng = @StrEng + @Str
    Set @Ch = Substring(@Word, @i + 1, 1)
    Set @z = @z + 1
END

return @StrEng

end

Please התחברות to join the conversation.

More
17 years 3 months ago #3593 by eldad
לדעתי הקוד הבא קצת יותר טוב ( יש דוגמאות ואפשר להשוות)


ALTER FUNCTION [dbo].[rev]
(
      @NAME VARCHAR(300)
)
RETURNS VARCHAR(300)
AS
BEGIN
      DECLARE @POS INT
      DECLARE @HebrewWord varchar(200)
      DECLARE @EnglishWord Varchar(200)
      DECLARE @NewName Varchar(200)
      DECLARE @Found int


set @HebrewWord = ''
set @EnglishWord = ''
set @Found = 0
set @NewName = ''
set @NAME  = ltrim(Rtrim(@NAME))

      SELECT @POS = 1
      WHILE @POS <= LEN(@NAME)
            --2
      BEGIN           
            if (ASCII(SUBSTRING(@NAME,@POS,1)) <> 32)
            begin
                  IF  (  ( (ASCII(SUBSTRING(@NAME,@POS,1)) < 224) and (ASCII(SUBSTRING(@NAME,@POS,1)) >= 65) )
  or ( (ASCII(SUBSTRING(@NAME,@POS,1)) < 224) and @Found = 0                          )
  or ( (ASCII(SUBSTRING(@NAME,@POS,1)) >= ascii('0') ) and (ASCII(SUBSTRING(@NAME,@POS,1)) <= ascii('9') ) ) 
  )
                  begin
                    SELECT @NAME = STUFF(@NAME, @POS, 1 , CHAR(ASCII(SUBSTRING(@NAME,@POS,1))))
                        set @EnglishWord = @EnglishWord + SUBSTRING(@NAME,@POS,1)
                        set @Found = 0
                  end 
                  else               
                  begin
                        set @HebrewWord = @HebrewWord + SUBSTRING(@NAME,@POS,1)
                        set @Found = 1
                  end
                      set @NewName =  reverse(@EnglishWord) +  ' ' + @HebrewWord

                  IF SUBSTRING(@NAME,@POS,1)= ''''
                  begin
                          SELECT @NAME = STUFF(@NAME, @POS, 1 , '`')     
                  end

      end
     
      else
      begin
            set @EnglishWord = @EnglishWord + ' '
            set @HebrewWord = @HebrewWord + ' '
      end
                  SELECT @POS = @POS + 1
    END

      RETURN REVERSE(ltrim(rtrim(@NewName))) --REVERSE (@HebrewWord) +@EnglishWord

END

go


declare @t as table ( name  varchar(200))

insert into @t (name) values ('COPAXON  לקידמ עבט י"ע')
insert into @t (name) values ('םלה ילגב לופיט אלל ץועי-טרופס')
insert into @t (name) values ('םצע חמ-DRB1 LOW RESOLUTION -תולתשה םואת')
insert into @t (name) values ('םצע חמ - DRB1 HIGH RESOLUTION - תולתשה םואת')
insert into @t (name) values ('מ"ק 100 דע ןטנ/סנלובמאב העסה')


select name ,dbo.rev(name) from @t

Please התחברות to join the conversation.

Moderators: eldad
Time to create page: 0.234 seconds