- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
using Microsoft.VisualBasic;
public string ConvertEnoviaNameForDB1(string name, char Separ = '%')
{
string functionReturnValue = null;
functionReturnValue = name;
//input filename
//check ENOVIA filenames (example c0234244 --.catpart or c0234244--.catpart)
//output filename in DB format for operator LIKE(c0234244 --.catpart -> c0234244%.catpart)
int i = 0;
int loc1 = Strings.InStr(name, ".CATP", CompareMethod.Text);
bool NeedToConvert = false;
char Chr1 = '1';
char ChrBefore1 = '1';
//check catparts and catproducts ONLY
if (loc1 > 0)
{
int NumSymbols = loc1 - 2;
if (NumSymbols > 6)
NumSymbols = 6;
string tmpstr1 = Strings.Mid(name, loc1 - NumSymbols - 1, NumSymbols);
//analyse 4 chars max
for (i = 0; i <= loc1 - 2; i++)
{
Chr1 = name[loc1 - 2 - i];
//3-string array start from 0(position = count-1)
if ((Strings.Asc(ChrBefore1) >= 65 & Strings.Asc(ChrBefore1) <= 90))
{
if (Chr1 == ' ')
{
i = i + 2;
break; // TODO: might not be correct. Was : Exit For
}
else if (Chr1 == '-')
{
ChrBefore1 = Chr1;
//means can be two chars (ex. "AA") max
}
else if ((Strings.Asc(Chr1) >= 65 & Strings.Asc(Chr1) <= 90) & i < 2)
{
ChrBefore1 = Chr1;
}
else
{
break; // TODO: might not be correct. Was : Exit For
}
}
else if (ChrBefore1 == '-')
{
if (Chr1 == ' ')
{
i = i + 2;
break; // TODO: might not be correct. Was : Exit For
// And i < 3 Then 'means can be "---" - not more
}
else if (Chr1 == '-')
{
//ChrBefore1 = Chr1
}
else
{
i = i + 1;
break; // TODO: might not be correct. Was : Exit For
}
//ChrBefore1 = Chr1
// means start
}
else if (ChrBefore1 == '1')
{
if (Chr1 == '-' | (Strings.Asc(Chr1) >= 65 & Strings.Asc(Chr1) <= 90))
{
ChrBefore1 = Chr1;
}
else
{
i = i + 1;
break; // TODO: might not be correct. Was : Exit For
}
}
}
functionReturnValue = Strings.Left(name, loc1 - i) + Separ + Strings.Right(name, Strings.Len(name) - loc1 + 1);
}
return functionReturnValue;
}
Наличие комментария в 7ой строчке приводит в неописуемый восторг.
Без него понимать поведение функции пришлось бы с болью.
И да, в RegExp могут не только лишь все. Мало кто может.