比较scilab中的外语字符串

时间:2018-07-29 20:09:49

标签: scilab

我正在尝试将输入字符串与文档中存在的字符串进行比较。我正在为此目的使用strcmp。这些是非英语字符串。当输入字符串为英语时,输出正确。但是对于任何卡纳达语(非英语)单词,输出都是相同的。我正在尝试编写一个程序来检查数据库中是否存在该单词。请指导我可能是什么问题。

调用函数如下:

str_kan = handles.InputBox.String;

res = strcmp('str_kan','s1.text')
if res == 1 then handles.InputBox.String = string( ' present')
    abort
else
     handles.InputBox.String = string( 'not present')
     abort
end

整个程序如下:

global s1

f=figure('figure_position',[400,50],'figure_size',[640,480],'auto_resize','on','background',[33],'figure_name','Graphic window number %d','dockable','off','infobar_visible','off','toolbar_visible','off','menubar_visible','off','default_axes','on','visible','off');

handles.dummy = 0;
handles.InputBox=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tunga','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.0929487,0.6568182,0.4647436,0.1795455],'Relief','default','SliderStep',[0.01,0.1],'String','Enter a Kannada Word','Style','edit','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','InputBox','Callback','')
handles.CheckDB=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.1025641,0.4636364,0.4567308,0.1204545],'Relief','default','SliderStep',[0.01,0.1],'String','Check','Style','pushbutton','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','CheckDB','Callback','CheckDB_callback(handles)')

f.visible = "on";

function CheckDB_callback(handles)
str_kan = handles.InputBox.String;

res = strcmp('str_kan','s1.text')
if res == 1 then handles.InputBox.String = string( ' present')
    abort
else
     handles.InputBox.String = string( 'not present')
     abort
end


endfunction

1 个答案:

答案 0 :(得分:0)

以下示例表明,在 Scilab 中,strcmp() 确实支持 UTF-8 扩展字符:

--> strcmp(["aα" "aα" "aβ"], ["aα" "aβ" "aα"])
 ans  =
   0.  -1.   1.

原始发布代码中的问题是字面值 "Hello" 和变量名称 Hello="my text" 之间的混淆,正如 PTRK 已经指出的那样。