Простая проблема с subseq (LISP)

Так как Вы используете TcpClient, который означает, что Вы проверяете открытые порты TCP. Существует много хороших объектов, доступных в Система. Сеть. Пространство имен NetworkInformation .

Использование эти IPGlobalProperties объект добраться до массива TcpConnectionInformation объекты, которые можно затем опросить о IP конечной точки и порте.

 int port = 456; //<--- This is your value
 bool isAvailable = true;

 // Evaluate current system tcp connections. This is the same information provided
 // by the netstat command line application, just in .Net strongly-typed object
 // form.  We will look through the list, and if our port we would like to use
 // in our TcpClient is occupied, we will set isAvailable to false.
 IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
 TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();

 foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
 {
   if (tcpi.LocalEndPoint.Port==port)
   {
     isAvailable = false;
     break;
   }
 }

 // At this point, if isAvailable is true, we can proceed accordingly.

6
задан thekidder 9 September 2009 в 14:37
поделиться

3 ответа

(defun include-start (line)
  "returns the string position after the '#include ' directive or nil if none"
  (let ((search-string "#include "))
    (when (search search-string line)
      (length search-string))))

(defun get-include (line)
  (let ((s (include-start line)))
    (when s
      (subseq line s))))
6
ответ дан 16 December 2019 в 21:43
поделиться

Я считаю, что заменить в строке намного проще.

(replace-in-string "#include <stdio.h>" "#include +" "")
    => "<stdio.h>"

Для вашего кода include-start возвращает начало совпадения, как следует из названия. Вы ищете include-end , который, вероятно, равен (+ (include-start ....) (length ....))

1
ответ дан 16 December 2019 в 21:43
поделиться
(defun get-include (s)
   (subseq s (mismatch "#include " s)))
1
ответ дан 16 December 2019 в 21:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: