Skip to content

Commit 6134a70

Browse files
authored
Index out of Range Exception
Remove the Line feed ('\n') character that is now sent by the Google translate API. This character was treated as an object that should be concatenated, causing data loss.
1 parent d342a9c commit 6134a70

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

GoogleTranslateApi/GoogleTranslate.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ public Block this[int x]
3434
{
3535
get
3636
{
37-
if (x > Blocks)
37+
if (x > Blocks - 1)
3838
throw new IndexOutOfRangeException("Index out of range");
3939
List<Block> _blocks = new List<Block>();
4040
foreach(object _data in Data)
4141
{
4242
if (_data is Block)
4343
{
44-
Block block = _data as Block? ?? throw new Exception("Cannot Parse the block at the given index");
45-
_blocks.Add(block);
44+
//Block block = _data as Block? ?? throw new Exception("Cannot Parse the block at the given index");
45+
_blocks.Add((Block)_data);
4646
}
4747
}
4848
return _blocks[x];
@@ -170,10 +170,10 @@ private string Download(string text)
170170

171171
public string Text(string text)
172172
{
173-
/* FIXED - Gets the multiples blocks that can be received */
174173
string Dest = string.Empty;
175-
176-
text = Download(text);
174+
/* FIXED - Remove '\n' (Line feed/new line char) */
175+
text = (Download(text)).Replace("\n", "");
176+
/* FIXED - Gets the multiples blocks that can be received */
177177
Block Datablock = new Block(text);
178178
for(int n = 0; n < Datablock[0][0].Blocks; n++)
179179
{

0 commit comments

Comments
 (0)