Google SOAP Search API - スペルチェック機能のサンプル(VB.NET) †
ここではコードのみを示します。説明は、C#のサンプルで行っています。
コード †
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
| | <%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click1(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim key As String = "XXXXXXXXXXXXXXXXXXX"
Dim gs As New Google.GoogleSearchService()
Dim suggestion As String = ""
Try
suggestion = gs.doSpellingSuggestion(key, TextBox1.Text)
Catch ex As System.Web.Services.Protocols.SoapException
TextBox2.Text = "エラー:" + ex.Message
Return
End Try
If suggestion <> "" Then
TextBox2.Text = suggestion
Else
TextBox2.Text = "提案はありません。"
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>スペルのチェック</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"
Text="スペルをチェックする文:">
</asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1"
Text="チェックを開始" /><br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="結果:">
</asp:Label><br />
<asp:TextBox ID="TextBox2" runat="server" ReadOnly="True">
</asp:TextBox><br />
<br />
</div>
</form>
</body>
</html>
|