在这个问题上,一个人提出了一个奇妙的ToDelimitedString扩展方法,该方法适用于IEnumerable:
Overriding ToString() of List<MyClass>
我正在尝试在Unity 3D 4.0中使用它,因为系统命名空间被覆盖会导致问题,到目前为止我已经做了绝对的引用:
public static string ToDelimitedString<T> (this IEnumerable<T> source) {
return source.ToDelimitedString (x => x.ToString (),
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator);
}
public static string ToDelimitedString<T> (this IEnumerable<T> source, System.Func<T, string> converter) {
return source.ToDelimitedString (converter,
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator);
}
public static string ToDelimitedString<T> (this IEnumerable<T> source, string separator) {
return source.ToDelimitedString (x => x.ToString (), separator);
}
public static string ToDelimitedString<T> (this IEnumerable<T> source, System.Func<T, string> converter, string separator) {
return string.Join (separator, source.Select (converter).ToArray ());
}
让我在Unity 3d中工作是我想要做的,我遇到的错误是:
Assets / Main / Extensions.cs(125,55):错误CS1061:输入System.Collections.Generic.IEnumerable<T>' does not contain a definition for
选择&#39;并且没有扩展方法Select' of type
System.Collections.Generic.IEnumerable&#39;可以找到(你错过了使用指令或程序集引用吗?)
注意我已经改变了一些,我无法克服的是&#34; source.Select&#34;我相信,这可能吗?谢谢,它使调试更容易,不必重写扩展,也许有助于序列化。
答案 0 :(得分:1)
您似乎错过了Linq命名空间。
你需要:
package com.github.davidepastore.stackoverflow34038430;
import java.io.IOException;
import java.net.URL;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
/**
* Stackoverflow 34038430 question.
*
*/
public class App {
public static void main(String[] args) throws IOException {
String url = "http://hdh.ucsd.edu/mobile/dining/locationmap.aspx?l=39";
Document document = Jsoup.connect(url).get();
String src = document.select("iframe").first().attr("src");
URL srcUrl = new URL(src);
String result = getParamValue(srcUrl.getQuery());
String[] coordinates = result.split(",");
Double latitude = Double.parseDouble(coordinates[0]);
Double longitude = Double.parseDouble(coordinates[1]);
System.out.println("Latitude: " + latitude);
System.out.println("Longitude: " + longitude);
}
/**
* Get the param value.
* @param query The query string.
* @return Returns the parameter value.
*/
public static String getParamValue(String query) {
String[] params = query.split("&");
for (String param : params) {
String name = param.split("=")[0];
if("q".equals(name)){
return param.split("=")[1];
}
}
return null;
}
}